Class: Nbp::Table

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/nbp/table.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type = "a") ⇒ Table

Returns a new instance of Table.



8
9
10
# File 'lib/nbp/table.rb', line 8

def initialize(type = "a")
  @index = self.class.index_of(type.downcase)
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



6
7
8
# File 'lib/nbp/table.rb', line 6

def index
  @index
end

Class Method Details

.indexObject



24
25
26
# File 'lib/nbp/table.rb', line 24

def self.index
  get("/dir.txt").split("\r\n")
end

.index_of(type) ⇒ Object



28
29
30
# File 'lib/nbp/table.rb', line 28

def self.index_of(type)
  index.select { |table_id| table_id.start_with?(type) }
end

.show(table_id) ⇒ Object



32
33
34
# File 'lib/nbp/table.rb', line 32

def self.show(table_id)
  get("/#{table_id}.xml").parsed_response
end

Instance Method Details

#after(table_id) ⇒ Object



16
17
18
# File 'lib/nbp/table.rb', line 16

def after(table_id)
  index.select { |id| index.index(id) > index.index(table_id) }
end

#before(table_id) ⇒ Object



20
21
22
# File 'lib/nbp/table.rb', line 20

def before(table_id)
  index.select { |id| index.index(id) < index.index(table_id) }
end

#latestObject



12
13
14
# File 'lib/nbp/table.rb', line 12

def latest
  self.class.show(index.last)
end