Class: SolarTerms24::SolarTerm

Inherits:
Object
  • Object
show all
Defined in:
lib/solar_terms_24/solar_term.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(solar_term_key, time, timezone: 'UTC', lang: :en) ⇒ SolarTerm

Returns a new instance of SolarTerm.



15
16
17
18
19
20
# File 'lib/solar_terms_24/solar_term.rb', line 15

def initialize(solar_term_key, time, timezone: 'UTC', lang: :en)
  @solar_term_key = solar_term_key
  @time = time
  @timezone = timezone
  @lang = lang
end

Instance Attribute Details

#langObject

Returns the value of attribute lang.



12
13
14
# File 'lib/solar_terms_24/solar_term.rb', line 12

def lang
  @lang
end

#solar_term_keyObject

Returns the value of attribute solar_term_key.



12
13
14
# File 'lib/solar_terms_24/solar_term.rb', line 12

def solar_term_key
  @solar_term_key
end

#timeObject (readonly)

Returns the value of attribute time.



13
14
15
# File 'lib/solar_terms_24/solar_term.rb', line 13

def time
  @time
end

#timezoneObject

Returns the value of attribute timezone.



12
13
14
# File 'lib/solar_terms_24/solar_term.rb', line 12

def timezone
  @timezone
end

Instance Method Details

#as_jsonObject



36
37
38
39
40
41
42
43
44
45
# File 'lib/solar_terms_24/solar_term.rb', line 36

def as_json
  {
    date: date.strftime('%Y-%m-%d'),
    datetime: datetime.strftime(SolarTerms24::Cache::TIME_FORMAT),
    lang: @lang,
    name: name,
    solar_term_key: @solar_term_key,
    timezone: @timezone
  }
end

#dateObject



27
28
29
# File 'lib/solar_terms_24/solar_term.rb', line 27

def date
  datetime.to_date
end

#datetimeObject



22
23
24
25
# File 'lib/solar_terms_24/solar_term.rb', line 22

def datetime
  tz = TZInfo::Timezone.get(@timezone)
  tz.to_local(@time)
end

#nameObject



31
32
33
34
# File 'lib/solar_terms_24/solar_term.rb', line 31

def name
  I18n.locale = @lang
  I18n.t(@solar_term_key)
end

#to_jsonObject



47
48
49
# File 'lib/solar_terms_24/solar_term.rb', line 47

def to_json
  JSON.pretty_generate(as_json)
end