Class: GData::Client::FusionTables::Data

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/fusion_tables/data/data.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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 options
  @headers = options[:headers]
  @body = options[:body]          
end

Instance Attribute Details

#bodyObject (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

#headersObject (readonly)

Returns the value of attribute headers.



21
22
23
# File 'lib/fusion_tables/data/data.rb', line 21

def headers
  @headers
end

#liveObject (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

#eachObject

Implement enumerable



59
60
61
# File 'lib/fusion_tables/data/data.rb', line 59

def each
  @body.each { |i| yield i }
end