Class: NpbFlash::Inning

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/npb_flash/inning.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, title, team) ⇒ Inning

Returns a new instance of Inning.



8
9
10
11
12
13
# File 'lib/npb_flash/inning.rb', line 8

def initialize(id, title, team)
  @id = id
  @title = title
  @team = team
  @events = []
end

Instance Attribute Details

#eventsObject

Returns the value of attribute events.



6
7
8
# File 'lib/npb_flash/inning.rb', line 6

def events
  @events
end

#idObject

Returns the value of attribute id.



6
7
8
# File 'lib/npb_flash/inning.rb', line 6

def id
  @id
end

#titleObject

Returns the value of attribute title.



6
7
8
# File 'lib/npb_flash/inning.rb', line 6

def title
  @title
end

Class Method Details

.from_node(node) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/npb_flash/inning.rb', line 51

def self.from_node(node)
  id = node['id']
  title = node.xpath('.//h3/b/text()')[0].text
  team = node['class'].split(' ')[1]
  inning = Inning.new(id, title, team)
  node.xpath('./ul/li').each do |li|
    raw_text = li.text
    text_index, text = raw_text.split(':', 2)
    inning.events.push(text)
  end
  inning
end

Instance Method Details

#<=>(other) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/npb_flash/inning.rb', line 31

def <=>(other)
  e =  self.inning_index <=> other.inning_index
  if e == 0
    if self.top?
      if other.top?
        e = 0
      else
        e = -1
      end
    else
      if other.top?
        e = 1
      else
        e = 0
      end
    end
  end
  e
end

#bottom?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/npb_flash/inning.rb', line 23

def bottom?
  not self.top?
end

#inningObject



27
28
29
# File 'lib/npb_flash/inning.rb', line 27

def inning
  [self.inning_index, self.top? ? :top : :bottom]
end

#inning_indexObject



15
16
17
# File 'lib/npb_flash/inning.rb', line 15

def inning_index
  @id.match(/[\d]+$/)[0].to_i
end

#top?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/npb_flash/inning.rb', line 19

def top?
  @id.match(/^[i]+/)[0].size == 1
end