Class: GoogleImageChart

Inherits:
Hashie::Dash
  • Object
show all
Defined in:
lib/google_image_chart.rb

Instance Method Summary collapse

Instance Method Details

#base64Object



33
34
35
# File 'lib/google_image_chart.rb', line 33

def base64
  Base64.encode64(image_data)
end

#chcoObject



80
81
82
# File 'lib/google_image_chart.rb', line 80

def chco
  colours && colours.join(',')
end

#chdObject



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/google_image_chart.rb', line 60

def chd
  result = ''

  first_data_group = data.slice(0,1).flatten
  result << 't:' << first_data_group.join(',')

  all_other_data_groups = data.slice(1,data.size)
  all_other_data_groups &&  all_other_data_groups.map { |values| result << '|' << values.join(',') }

  result
end

#chdlObject



94
95
96
# File 'lib/google_image_chart.rb', line 94

def chdl
  legend_labels && legend_labels.join('|')
end

#chlsObject



72
73
74
# File 'lib/google_image_chart.rb', line 72

def chls
  line_styles && line_styles.join('|')
end

#chmObject



84
85
86
# File 'lib/google_image_chart.rb', line 84

def chm
  markers && markers.join('|')
end

#chmaObject



76
77
78
# File 'lib/google_image_chart.rb', line 76

def chma
  margins && margins.map { |group| group.join(',') }.join('|')
end

#chsObject



48
49
50
# File 'lib/google_image_chart.rb', line 48

def chs
  "#{width}x#{height}"
end

#chxlObject



88
89
90
91
92
# File 'lib/google_image_chart.rb', line 88

def chxl
  labels && labels.each_with_index.inject([]) { |result, (labels, index)|
    result << "#{index}:|#{labels.join('|')}"
  }.join(',')
end

#chxrObject



56
57
58
# File 'lib/google_image_chart.rb', line 56

def chxr
  axes_range && axes_range.join(',')
end

#chxsObject



98
99
100
# File 'lib/google_image_chart.rb', line 98

def chxs
  label_styles && label_styles.join(',')
end

#chxtObject



52
53
54
# File 'lib/google_image_chart.rb', line 52

def chxt
  axes && axes.join(',')
end

#image_dataObject



27
28
29
30
31
# File 'lib/google_image_chart.rb', line 27

def image_data
  Net::HTTP.get(
    URI.parse(url)
  )
end

#propertiesObject



37
38
39
40
41
42
43
44
45
46
# File 'lib/google_image_chart.rb', line 37

def properties
  %w[
    cht chs chma chco chxt chxr chls chxl chxs chdl chdlp chd chm
  ].inject([]) { |result, property|
    if value = self.send(property)
      result << "#{property}=#{value}"
    end
    result
  }.join("&")
end

#urlObject



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

def url
  URI.escape("#{baseurl}#{properties}")
end