Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

strptime and ruby 1.8.7 #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions lib/vendors/apple_vendor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,24 @@ def check
@warranties = []

if json["ERROR_CODE"].nil?

@warranties << {
:description => sprintf("%s - %s", json["PROD_DESCR"].strip, json["PH_SUPPORT_COVERAGE_SUBHEADER"].split(':').first.strip),
:expired => json["PH_SUPPORT_COVERAGE_SUBHEADER"].split(':').last.strip == "Expired",
:expire_date => (" " * 10),
:details => json
}

@warranties << {
:description => sprintf("%s - %s", json["PROD_DESCR"].strip, json["HW_REPAIR_COVERAGE_SUBHEADER"].split(':').first.strip),
:expired => json["HW_REPAIR_COVERAGE_SUBHEADER"].split(':').last.strip == "Expired",
:expire_date => (" " * 10),
:details => json
}

w1 = Warranty.new()
w1.description = sprintf("%s - %s", json["PROD_DESCR"].strip,
json["PH_SUPPORT_COVERAGE_SUBHEADER"].split(':').first.strip)
w1.expired = json["PH_SUPPORT_COVERAGE_SUBHEADER"].split(':').last.strip == "Expired"
w1.expire_date = (" " * 10)
w1.details = json
@warranties << w1
w2 = Warranty.new()
w2.description = sprintf("%s - %s", json["PROD_DESCR"].strip,
json["HW_REPAIR_COVERAGE_SUBHEADER"].split(':').first.strip)
w2.expired = json["HW_REPAIR_COVERAGE_SUBHEADER"].split(':').last.strip == "Expired"
w2.expire_date = (" " * 10)
w2.details = json
@warranties << w2
end
end


end

end
end
14 changes: 12 additions & 2 deletions lib/vendors/base_vendor.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
require 'net/http'
require 'net/https'
require 'uri'
require 'nokogiri'
require 'json'
require 'time'

require 'date'
require 'pry'

module WarrantyCheck
Expand Down Expand Up @@ -47,6 +48,15 @@ def html
@html ||= get_html
end

def warrantystatus
# return true when at least one warranty is still valid
validwarranty = false
@warranties.each do | w |
validwarranty = true if w.expired == false
end
return validwarranty
end

def dom
@dom ||= Nokogiri::HTML(html)
end
Expand Down Expand Up @@ -75,4 +85,4 @@ def get_html

end

end
end
27 changes: 11 additions & 16 deletions lib/vendors/dell_vendor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,23 @@ def check

details_description = tds[0].text.strip
details_provider = tds[1].text.strip
details_start_date = Time.strptime(tds[2].text.strip, "%m/%d/%Y")
details_end_date = Time.strptime(tds[3].text.strip, "%m/%d/%Y")
details_start_date = Date.strptime(tds[2].text.strip, "%m/%d/%Y")
details_end_date = Date.strptime(tds[3].text.strip, "%m/%d/%Y")
details_days_left = tds[4].text.strip.to_i

warranty = {
:description => "#{details_description} (#{details_provider})",
:expired => (details_days_left == 0 ? true : false),
:expire_date => details_end_date,

:details => {
:description => details_description,
:provider => details_provider ,
:start_date => details_start_date ,
:end_date => details_end_date ,
:days_left => details_days_left
}
}
warranty = Warranty.new()
warranty.description = "#{details_description} (#{details_provider})"
warranty.expired = (details_days_left == 0 ? true : false)
warranty.expire_date = details_end_date
warranty.provider = details_provider
warranty.start_date = details_start_date
warranty.end_date = details_end_date
warranty.days_left = details_days_left

@warranties << warranty
end
end

end

end
end
15 changes: 6 additions & 9 deletions lib/vendors/fujitsu_vendor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,14 @@ def check

return if td1 =~ /^Error/

expiration_date = Time.strptime(td3, "%d/%m/%Y")

warranty = {
:description => sprintf("%s - %s", td1, td2),
:expired => (expiration_date < Time.now ? true : false),
:expire_date => expiration_date
}

expiration_date = Date.strptime(td3, "%d/%m/%Y")
warranty = Warranty.new()
warranty.description = sprintf("%s - %s", td1, td2)
warranty.expired = (expiration_date < Time.now ? true : false)
warranty.expire_date = expiration_date
@warranties << warranty
end

end

end
end
44 changes: 21 additions & 23 deletions lib/vendors/hp_vendor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,33 @@ def check

@warranty_type ||= (tds.size == 7 ? tds[0].text.strip : nil)
n = (tds.size == 7 ? 0 : -1)

details_warranty_type = @warranty_type
details_service_type = tds[n+1].text.strip
details_start_date = Time.strptime(tds[n+2].text.strip, "%d %b %Y")
details_end_date = Time.strptime(tds[n+3].text.strip, "%d %b %Y")
details_status = tds[n+4].text.strip
details_service_level = tds[n+5].text.strip
details_deliverables = tds[n+6].text.strip
details_warranty_type = @warranty_type.gsub(/[\t\n\r]+/, "")
details_service_type = tds[n+1].text.strip.gsub(/[\t\n\r]+/, "")
details_start_date = Date.strptime(tds[n+2].text.strip, "%d %b %Y")
details_end_date = Date.strptime(tds[n+3].text.strip, "%d %b %Y")
details_status = tds[n+4].text.strip.gsub(/\s+/, "")
details_service_level = tds[n+5].text.strip.gsub(/\st+/, "")
details_deliverables = tds[n+6].text.strip.gsub(/[\t\n\r]+/, "")

# create new warranty object

warranty = {
:description => "#{details_warranty_type} - #{details_service_type}",
:expired => (details_status == "Expired" ? true : false),
:expire_date => details_end_date,
warranty = Warranty.new()
warranty.description = "#{details_warranty_type} - #{details_service_type}"
warranty.expired = (details_status == "Expired" ? true : false)
warranty.warranty_type = details_warranty_type
warranty.service_type = details_service_type
warranty.start_date = details_start_date
warranty.end_date = details_end_date
warranty.status = details_status
warranty.service_level = details_service_level
warranty.deliverables = details_deliverables

:details => {
:warranty_type => details_warranty_type,
:service_type => details_service_type ,
:start_date => details_start_date ,
:end_date => details_end_date ,
:status => details_status ,
:service_level => details_service_level,
:deliverables => details_deliverables ,
}
}


@warranties << warranty
end
end

end

end
end
27 changes: 12 additions & 15 deletions lib/vendors/ibm_vendor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,22 @@ def check
details_type_model = tds1[2].text.strip
details_serial_number = tds1[4].text.strip
details_location = tds2[0].text.strip
details_expiration_date = Time.strptime(tds2[2].text.strip, "%Y-%m-%d")
details_expiration_date = Date.strptime(tds2[2].text.strip, "%Y-%m-%d")

warranty = {
:description => "",
:expired => (details_expiration_date < Time.now ? true : false),
:expire_date => details_expiration_date,

:details => {
:product_id => details_product_id ,
:type_model => details_type_model ,
:serial_number => details_serial_number ,
:location => details_location ,
:expiration_date => details_expiration_date,
}
}
warranty = Warranty.new()
warranty.description = ""
warranty.expired = (details_expiration_date < Time.now ? true : false)
warranty.expire_date = details_expiration_date
warranty.product_id = details_product_id ,
warranty.type_model = details_type_model ,
warranty.serial_number = details_serial_number ,
warranty.location = details_location ,
warranty.expiration_date = details_expiration_date,


@warranties << warranty
end

end

end
end
3 changes: 2 additions & 1 deletion lib/warranty-check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
require 'vendors/ibm_vendor'
require 'vendors/apple_vendor'
require 'vendors/fujitsu_vendor'
require 'warranty'
require 'classify'

require 'classify'
28 changes: 28 additions & 0 deletions lib/warranty.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module WarrantyCheck

class Warranty
attr_accessor :description, :expired, :expire_date, :warrantydetails,
:warranty_type, :status, :service_level, :deliverables, :product_id, :serial_number,
:location, :service_type, :type_model, :start_date, :end_date, :details,
:provider, :days_left, :expiration_date

def warrantydetails
# this method is just a summary of the details as the individual details can be accessed by themselves
if @warrantydetails.nil?
@warrantydetails = {
"warranty_type" => @warranty_type,
"service_type" => @service_type,
"start_date" => @start_date,
"end_date" => @end_date,
"status" => @status,
"service_level" => @service_level,
"deliverables" => @deliverables,
}
end
return @warrantydetails

end

end

end