Class: Sekki24::Kou

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/sekki24/kou.rb

Constant Summary collapse

ATTRIBUTES =
%i[ordinal name_ja reading longitude term_key position time].freeze

Instance Method Summary collapse

Constructor Details

#initialize(definition:, time:) ⇒ Kou

Returns a new instance of Kou.



11
12
13
14
15
16
17
18
19
20
# File 'lib/sekki24/kou.rb', line 11

def initialize(definition:, time:)
  @ordinal = definition.ordinal
  @name_ja = definition.name_ja
  @reading = definition.reading
  @longitude = definition.longitude
  @term_key = definition.term_key
  @position = definition.position
  @time = time.dup.freeze
  freeze
end

Instance Method Details

#<=>(other) ⇒ Object



22
23
24
25
26
# File 'lib/sekki24/kou.rb', line 22

def <=>(other)
  return unless other.respond_to?(:time)

  time <=> other.time
end

#==(other) ⇒ Object Also known as: eql?



28
29
30
# File 'lib/sekki24/kou.rb', line 28

def ==(other)
  other.is_a?(Kou) && ordinal == other.ordinal && time == other.time
end

#hashObject



33
34
35
# File 'lib/sekki24/kou.rb', line 33

def hash
  [self.class, ordinal, time].hash
end

#inspectObject



45
46
47
# File 'lib/sekki24/kou.rb', line 45

def inspect
  "#<#{self.class}#{ordinal}#{name_ja} #{time.iso8601} longitude=#{longitude}°>"
end

#to_dateObject



37
38
39
# File 'lib/sekki24/kou.rb', line 37

def to_date
  time.to_date
end

#to_hObject



41
42
43
# File 'lib/sekki24/kou.rb', line 41

def to_h
  ATTRIBUTES.to_h { |attribute| [attribute, public_send(attribute)] }
end