Class: WorldbankAsDataframe::Data

Inherits:
Object
  • Object
show all
Extended by:
Queriable
Defined in:
lib/worldbank_as_dataframe/data.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Queriable

format, income_level, language, lending_type, most_recent_values, page, per_page, region

Constructor Details

#initialize(values = {}) ⇒ Data

Returns a new instance of Data.



28
29
30
31
32
33
34
35
36
# File 'lib/worldbank_as_dataframe/data.rb', line 28

def initialize(values={})
  @raw = values
  @name = values['indicator'].delete('value')
  @id = values['indicator'].delete('id')
  @value = values.delete('value')
  @date = values.delete('date')
  values.delete('indicator')
  @others = values
end

Instance Attribute Details

#dateObject (readonly)

Returns the value of attribute date.



6
7
8
# File 'lib/worldbank_as_dataframe/data.rb', line 6

def date
  @date
end

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/worldbank_as_dataframe/data.rb', line 6

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/worldbank_as_dataframe/data.rb', line 6

def name
  @name
end

#othersObject (readonly)

Returns the value of attribute others.



6
7
8
# File 'lib/worldbank_as_dataframe/data.rb', line 6

def others
  @others
end

#rawObject (readonly)

Returns the value of attribute raw.



6
7
8
# File 'lib/worldbank_as_dataframe/data.rb', line 6

def raw
  @raw
end

#valueObject (readonly)

Returns the value of attribute value.



6
7
8
# File 'lib/worldbank_as_dataframe/data.rb', line 6

def value
  @value
end

Class Method Details

.allObject



20
21
22
# File 'lib/worldbank_as_dataframe/data.rb', line 20

def self.all
  find('all')
end

.country(arg) ⇒ Object



12
13
14
# File 'lib/worldbank_as_dataframe/data.rb', line 12

def self.country(arg)
  find('all').country(arg)
end

.fetch(arg) ⇒ Object



16
17
18
# File 'lib/worldbank_as_dataframe/data.rb', line 16

def self.fetch(arg)
  find(arg).fetch
end

.find(id) ⇒ Object



24
25
26
# File 'lib/worldbank_as_dataframe/data.rb', line 24

def self.find(id)
  WorldbankAsDataframe::DataQuery.new('indicator', id, self)
end

.rawObject



8
9
10
# File 'lib/worldbank_as_dataframe/data.rb', line 8

def self.raw
  find('all').raw
end

Instance Method Details

#to_hObject



38
39
40
41
42
43
44
45
# File 'lib/worldbank_as_dataframe/data.rb', line 38

def to_h
  hdr = @name
  suffix = nil
  suffix = " for #{@others['country']['value']}" rescue ''
  hdr += suffix

  {'Timestamps' => Date.new(@date.to_i, 12, 31), hdr => @value }
end