Class: Springpad::Blocks::Task
- Inherits:
-
Object
- Object
- Springpad::Blocks::Task
- Defined in:
- lib/springpad/blocks/task.rb
Overview
Instance Attribute Summary collapse
-
#category ⇒ Object
readonly
Returns the value of attribute category.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
-
.process(json) ⇒ Object
Public: Converts a Hash of JSON task blocks to an Array of actual Task instances.
Instance Method Summary collapse
-
#initialize(name, description, category = "") ⇒ Task
constructor
Internal: Initializes a new Task.
-
#render ⇒ Object
Public: Renders a task to the standard output.
-
#to_params(shard) ⇒ Object
Public: Creates a query to create a Task in Springpad.
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
#category ⇒ Object (readonly)
Returns the value of attribute category.
11 12 13 |
# File 'lib/springpad/blocks/task.rb', line 11 def category @category end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
11 12 13 |
# File 'lib/springpad/blocks/task.rb', line 11 def description @description end |
#name ⇒ Object (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
#render ⇒ Object
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 |