Class: GData::Client::FusionTables::Data
- Inherits:
-
Object
- Object
- GData::Client::FusionTables::Data
- Includes:
- Enumerable
- Defined in:
- lib/fusion_tables/data/data.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
(also: #to_h)
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#live ⇒ Object
readonly
Returns the value of attribute live.
Class Method Summary collapse
-
.parse(response) ⇒ Object
Reads in CSV.
Instance Method Summary collapse
-
#each ⇒ Object
Implement enumerable.
-
#initialize(options) ⇒ Data
constructor
configures headers hash and sets up.
Constructor Details
#initialize(options) ⇒ Data
configures headers hash and sets up
25 26 27 28 |
# File 'lib/fusion_tables/data/data.rb', line 25 def initialize @headers = [:headers] @body = [:body] end |
Instance Attribute Details
#body ⇒ Object (readonly) Also known as: to_h
Returns the value of attribute body.
21 22 23 |
# File 'lib/fusion_tables/data/data.rb', line 21 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
21 22 23 |
# File 'lib/fusion_tables/data/data.rb', line 21 def headers @headers end |
#live ⇒ Object (readonly)
Returns the value of attribute live.
21 22 23 |
# File 'lib/fusion_tables/data/data.rb', line 21 def live @live end |
Class Method Details
.parse(response) ⇒ Object
Reads in CSV
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/fusion_tables/data/data.rb', line 31 def self.parse response body = [] headers = [] first = true if CSV.const_defined? :Reader CSV::Reader.parse(response.body) do |row| if first first = false headers = row.map { |x|x.strip.downcase.gsub(" ","_").to_sym } next end body << Hash[*headers.zip(row).flatten] end else CSV.parse(response.body) do |row| if first first = false headers = row.map { |x|x.strip.downcase.gsub(" ","_").to_sym } next end body << Hash[*headers.zip(row).flatten] end end self.new :headers => headers, :body => body end |
Instance Method Details
#each ⇒ Object
Implement enumerable
59 60 61 |
# File 'lib/fusion_tables/data/data.rb', line 59 def each @body.each { |i| yield i } end |