Class: Springpad::Blocks::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/springpad/blocks/task.rb

Overview

Public: Maps to a Springpad Task block.

Examples

Blocks::Task.process(json_tasks)
# => [#<Blocks::Task>..., #<Blocks::Task...>,]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, description, category = "") ⇒ Task

Internal: Initializes a new Task.

name - the String name description - the String description category - the String category



33
34
35
36
37
# File 'lib/springpad/blocks/task.rb', line 33

def initialize(name, description, category="")
  @name        = name
  @description = description
  @category    = category
end

Instance Attribute Details

#categoryObject (readonly)

Returns the value of attribute category.



11
12
13
# File 'lib/springpad/blocks/task.rb', line 11

def category
  @category
end

#descriptionObject (readonly)

Returns the value of attribute description.



11
12
13
# File 'lib/springpad/blocks/task.rb', line 11

def description
  @description
end

#nameObject (readonly)

Returns the value of attribute name.



11
12
13
# File 'lib/springpad/blocks/task.rb', line 11

def name
  @name
end

Class Method Details

.process(json) ⇒ Object

Public: Converts a Hash of JSON task blocks to an Array of actual Task instances.

json - the Hash JSON with the task blocks

Returns an Array of Tasks.



18
19
20
21
22
23
24
25
26
# File 'lib/springpad/blocks/task.rb', line 18

def self.process(json)
  json.map do |task|
    Task.new(
      task['name'],
      task['properties']['description'],
      task['properties']['category']['name']
    )
  end
end

Instance Method Details

#renderObject

Public: Renders a task to the standard output.

Returns nothing.



42
43
44
45
46
47
48
49
50
# File 'lib/springpad/blocks/task.rb', line 42

def render
  out = HighLine.new
  out.wrap_at = 78
  out.say <<-RENDER
<%=color("#{@name}", :bold)%> [#{@category.upcase}]
<%='-'*#{@name.length}%>
#{@description}
RENDER
end

#to_params(shard) ⇒ Object

Public: Creates a query to create a Task in Springpad.

shard - the String user shard.

Returns the String JSON commands.



57
58
59
60
61
62
63
64
65
# File 'lib/springpad/blocks/task.rb', line 57

def to_params(shard)
  uuid = "/UUID(#{shard}3#{SecureRandom.uuid[3..-1]})/"
  [
    ["create", "Note", uuid],
    ["set", uuid, "name", @name],
    ["set", uuid, "description", @description],
    ["set", uuid, "category", @category]
  ].to_json
end