Class: SolarTerms24::SolarTerm
- Inherits:
-
Object
- Object
- SolarTerms24::SolarTerm
- Defined in:
- lib/solar_terms_24/solar_term.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#lang ⇒ Object
Returns the value of attribute lang.
-
#solar_term_key ⇒ Object
Returns the value of attribute solar_term_key.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
-
#timezone ⇒ Object
Returns the value of attribute timezone.
Instance Method Summary collapse
- #as_json ⇒ Object
- #date ⇒ Object
- #datetime ⇒ Object
-
#initialize(solar_term_key, time, timezone: 'UTC', lang: :en) ⇒ SolarTerm
constructor
A new instance of SolarTerm.
- #name ⇒ Object
- #to_json ⇒ Object
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
#lang ⇒ Object
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_key ⇒ Object
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 |
#time ⇒ Object (readonly)
Returns the value of attribute time.
13 14 15 |
# File 'lib/solar_terms_24/solar_term.rb', line 13 def time @time end |
#timezone ⇒ Object
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_json ⇒ Object
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 |
#date ⇒ Object
27 28 29 |
# File 'lib/solar_terms_24/solar_term.rb', line 27 def date datetime.to_date end |
#datetime ⇒ Object
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 |
#name ⇒ Object
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_json ⇒ Object
47 48 49 |
# File 'lib/solar_terms_24/solar_term.rb', line 47 def to_json JSON.pretty_generate(as_json) end |