Class: Denso::Calendar

Inherits:
Object
  • Object
show all
Defined in:
lib/denso/calendar.rb,
lib/denso/calendar/cli.rb,
lib/denso/calendar/date.rb,
lib/denso/calendar/version.rb,
lib/denso/calendar/formatter.rb,
lib/denso/calendar/formatter/ical.rb,
lib/denso/calendar/formatter/plain.rb

Defined Under Namespace

Modules: Formatter Classes: Cli, Date

Constant Summary collapse

URI =
'https://www.denso.com/jp/ja/about-us/calendar/'
VERSION =
"0.2.0"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tables_doc) ⇒ Calendar

Returns a new instance of Calendar.



35
36
37
38
39
# File 'lib/denso/calendar.rb', line 35

def initialize(tables_doc)
  @doc = tables_doc

  parse
end

Instance Attribute Details

#daysArray[Denso::Calendar::Date] (readonly)

Returns:



33
34
35
# File 'lib/denso/calendar.rb', line 33

def days
  @days
end

Class Method Details

.load(type = :production) ⇒ Array[Denso::Calendar]

Loads calendars from DENSO site

Parameters:

  • type (Symbol) (defaults to: :production)

    A calender type.

Returns:

See Also:



20
21
22
23
24
25
26
# 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

.uriObject



28
29
30
# File 'lib/denso/calendar.rb', line 28

def self.uri
  @uri ||= ::URI.parse(URI)
end

Instance Method Details

#business_daysArray[Denso::Calendar::Date]

Returns all business days in the Calendar



45
46
47
# File 'lib/denso/calendar.rb', line 45

def business_days
  @business_days ||= days.select(&:business_day?)
end

#holidaysArray[Denso::Calendar::Date]

Returns all holidays in the Calendar



53
54
55
# File 'lib/denso/calendar.rb', line 53

def holidays
  @holidays ||= days.select(&:holiday?)
end