class Denso::Calendar
Constants
- URI
- VERSION
Attributes
days[R]
@return [Array]
Public Class Methods
load(type = :production)
click to toggle source
Loads calendars from DENSO site
@param type [Symbol] A calender type. @return [Array] @see Denso::Calendar::URI
# File lib/denso/calendar.rb, line 20 def self.load(type = :production) content = Net::HTTP.get(uri) doc = Nokogiri::HTML(content) tables = doc.xpath("//h2/a[@id='#{type}']/../../following-sibling::div[contains(@class, 'denso-calendar')][1]") Calendar.new(tables) end
new(tables_doc)
click to toggle source
# File lib/denso/calendar.rb, line 35 def initialize(tables_doc) @doc = tables_doc parse end
uri()
click to toggle source
# File lib/denso/calendar.rb, line 28 def self.uri @uri ||= ::URI.parse(URI) end
Public Instance Methods
business_days()
click to toggle source
Returns all business days in the Calendar
@return [Array] @see Denso::Calendar::Date#business_day?
# File lib/denso/calendar.rb, line 45 def business_days @business_days ||= days.select(&:business_day?) end
holidays()
click to toggle source
Returns all holidays in the Calendar
@return [Array] @see Denso::Calendar::Date#holiday?
# File lib/denso/calendar.rb, line 53 def holidays @holidays ||= days.select(&:holiday?) end
Private Instance Methods
parse()
click to toggle source
# File lib/denso/calendar.rb, line 59 def parse @days = [] @doc.xpath('.//table').each do |table| caption = table.xpath('./caption/text()').to_s m = caption.match(/(\d{4})年(\d{1,2})月/) year = m[1].to_i month = m[2].to_i table.css('td').each do |element| day = element.content next if day !~ /\A\d+\Z/ holiday = element['class'] && element['class'].include?('holiday') @days << Denso::Calendar::Date.new(year, month, day.to_i, holiday: holiday) end end end