Class: Springpad::Blocks::Note
- Inherits:
-
Object
- Object
- Springpad::Blocks::Note
- Defined in:
- lib/springpad/blocks/note.rb
Overview
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Class Method Summary collapse
-
.process(json) ⇒ Object
Public: Converts a Hash of JSON note blocks to an Array of actual Note instances.
Instance Method Summary collapse
-
#initialize(name, text) ⇒ Note
constructor
Internal: Initializes a new Note.
-
#render ⇒ Object
Public: Renders a note to the standard output.
-
#to_params(shard) ⇒ Object
Public: Creates a query to create a Note in Springpad.
Constructor Details
#initialize(name, text) ⇒ Note
Internal: Initializes a new Note.
name - the String name text - the String text content
35 36 37 38 |
# File 'lib/springpad/blocks/note.rb', line 35 def initialize(name, text) @name = name @text = text end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
15 16 17 |
# File 'lib/springpad/blocks/note.rb', line 15 def name @name end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
15 16 17 |
# File 'lib/springpad/blocks/note.rb', line 15 def text @text end |
Class Method Details
.process(json) ⇒ Object
Public: Converts a Hash of JSON note blocks to an Array of actual Note instances.
json - the Hash JSON with the note blocks
Returns an Array of Notes.
22 23 24 25 26 27 28 29 |
# File 'lib/springpad/blocks/note.rb', line 22 def self.process(json) json.map do |note| Note.new( note['name'] || "(no title)", note['properties']['text'] ) end end |
Instance Method Details
#render ⇒ Object
Public: Renders a note to the standard output.
Returns nothing.
43 44 45 46 47 48 49 50 51 |
# File 'lib/springpad/blocks/note.rb', line 43 def render out = HighLine.new out.wrap_at = 78 out.say <<-RENDER <%=color("#{@name}", :bold)%> <%='-'*#{@name.length}%> #{@text} RENDER end |
#to_params(shard) ⇒ Object
Public: Creates a query to create a Note in Springpad.
shard - the String user shard.
Returns the String JSON commands.
58 59 60 61 62 63 64 65 |
# File 'lib/springpad/blocks/note.rb', line 58 def to_params(shard) uuid = "/UUID(#{shard}3#{SecureRandom.uuid[3..-1]})/" [ ["create", "Note", uuid], ["set", uuid, "name", @name], ["set", uuid, "text", @text] ].to_json end |