Class: Gspush
- Inherits:
-
Object
- Object
- Gspush
- 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
-
#delimiter ⇒ Object
readonly
Returns the value of attribute delimiter.
-
#lines ⇒ Object
readonly
Returns the value of attribute lines.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(url, options = {}) ⇒ Gspush
constructor
A new instance of Gspush.
- #parse_lines ⇒ Object
- #push(line) ⇒ Object
- #save ⇒ Object
- #separate(line) ⇒ Object
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, = {}) @url = url @delimiter = [:delimiter] @nullpush = [:nullpush] @username = [:username] @password = [:password] @oauth2 = [:oauth2] @oauth_token_file = [:oauth_token_file] @prepend_timestamp = [:prepend_timestamp] @sheet_title = [:sheet_title] @lines = [] end |
Instance Attribute Details
#delimiter ⇒ Object (readonly)
Returns the value of attribute delimiter.
13 14 15 |
# File 'lib/gspush.rb', line 13 def delimiter @delimiter end |
#lines ⇒ Object (readonly)
Returns the value of attribute lines.
13 14 15 |
# File 'lib/gspush.rb', line 13 def lines @lines end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
13 14 15 |
# File 'lib/gspush.rb', line 13 def url @url end |
Instance Method Details
#parse_lines ⇒ Object
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 |
#save ⇒ Object
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 |