Class: Sekki24::Term
Constant Summary collapse
- ATTRIBUTES =
%i[key name_ja reading name_en name_zh longitude time].freeze
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(definition:, time:) ⇒ Term
constructor
A new instance of Term.
- #inspect ⇒ Object
- #to_date ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(definition:, time:) ⇒ Term
Returns a new instance of Term.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/sekki24/term.rb', line 14 def initialize(definition:, time:) @key = definition.key @name_ja = definition.name_ja @reading = definition.reading @name_en = definition.name_en @name_zh = definition.name_zh @longitude = definition.longitude @time = time.dup.freeze freeze end |
Instance Method Details
#<=>(other) ⇒ Object
25 26 27 28 29 |
# File 'lib/sekki24/term.rb', line 25 def <=>(other) return unless other.respond_to?(:time) time <=> other.time end |
#==(other) ⇒ Object Also known as: eql?
31 32 33 |
# File 'lib/sekki24/term.rb', line 31 def ==(other) other.is_a?(Term) && key == other.key && time == other.time end |
#hash ⇒ Object
36 37 38 |
# File 'lib/sekki24/term.rb', line 36 def hash [self.class, key, time].hash end |
#inspect ⇒ Object
48 49 50 |
# File 'lib/sekki24/term.rb', line 48 def inspect "#<#{self.class} #{name_ja} (#{key}) #{time.iso8601} longitude=#{longitude}°>" end |
#to_date ⇒ Object
40 41 42 |
# File 'lib/sekki24/term.rb', line 40 def to_date time.to_date end |
#to_h ⇒ Object
44 45 46 |
# File 'lib/sekki24/term.rb', line 44 def to_h ATTRIBUTES.to_h { |attribute| [attribute, public_send(attribute)] } end |