Class: Gspush

Inherits:
Object
  • Object
show all
Defined in:
lib/gspush.rb,
lib/gspush/oauth2.rb,
lib/gspush/version.rb

Defined Under Namespace

Classes: CLI, Oauth2, WorksheetNotFound

Constant Summary collapse

VERSION =
"0.0.2"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, options = {}) ⇒ Gspush

Returns a new instance of Gspush.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/gspush.rb', line 15

def initialize(url, options = {})
  @url = url

  @delimiter = options[:delimiter]
  @nullpush  = options[:nullpush]
  @username  = options[:username]
  @password  = options[:password]

  @oauth2 = options[:oauth2]
  @oauth_token_file = options[:oauth_token_file]

  @prepend_timestamp = options[:prepend_timestamp]
  @sheet_title = options[:sheet_title]

  @lines = []
end

Instance Attribute Details

#delimiterObject (readonly)

Returns the value of attribute delimiter.



13
14
15
# File 'lib/gspush.rb', line 13

def delimiter
  @delimiter
end

#linesObject (readonly)

Returns the value of attribute lines.



13
14
15
# File 'lib/gspush.rb', line 13

def lines
  @lines
end

#urlObject (readonly)

Returns the value of attribute url.



13
14
15
# File 'lib/gspush.rb', line 13

def url
  @url
end

Instance Method Details

#parse_linesObject



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

def parse_lines
  now = Time.now.strftime("%Y-%m-%d %H:%M:%S")
  @lines.each_with_object([]) {|line, obj|
    values = separate(line)
    if @prepend_timestamp
      values.unshift(now)
    end
    unless values.empty?
      obj << values
    end
  }
end

#push(line) ⇒ Object



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

def push(line)
  @lines.push line
end

#saveObject

Raises:



49
50
51
52
53
54
55
# File 'lib/gspush.rb', line 49

def save
  spreadsheet = open(@url)

  sheet = select_worksheet(spreadsheet)
  raise WorksheetNotFound if sheet.nil?
  update(sheet, parse_lines)
end

#separate(line) ⇒ Object



57
58
59
# File 'lib/gspush.rb', line 57

def separate(line)
  line.split(@delimiter)
end