Module: MPS::Element
- Included in:
- MPS::Elements::Log, MPS::Elements::MPS, MPS::Elements::Note, MPS::Elements::Reminder, MPS::Elements::Task
- Defined in:
- lib/mps/elements/element.rb
Constant Summary collapse
- PADDING =
' '
Instance Attribute Summary collapse
-
#body_str ⇒ Object
readonly
Returns the value of attribute body_str.
-
#disp_str ⇒ Object
Returns the value of attribute disp_str.
-
#parsed_args ⇒ Object
readonly
Returns the value of attribute parsed_args.
-
#raw_args ⇒ Object
readonly
Returns the value of attribute raw_args.
Class Method Summary collapse
-
.split_args(raw) ⇒ Object
Parses “work, release, status: done” → { attrs: { status: “done” }, tags: [“work”, “release”] } Parts containing “:” become named attrs; bare words become tags.
Instance Method Summary collapse
- #display_str(padding_size = @refs.size - 1) ⇒ Object
- #initialize(args:, refs:, body_str:) ⇒ Object
- #tags ⇒ Object
Instance Attribute Details
#body_str ⇒ Object (readonly)
Returns the value of attribute body_str.
27 28 29 |
# File 'lib/mps/elements/element.rb', line 27 def body_str @body_str end |
#disp_str ⇒ Object
Returns the value of attribute disp_str.
26 27 28 |
# File 'lib/mps/elements/element.rb', line 26 def disp_str @disp_str end |
#parsed_args ⇒ Object (readonly)
Returns the value of attribute parsed_args.
27 28 29 |
# File 'lib/mps/elements/element.rb', line 27 def parsed_args @parsed_args end |
#raw_args ⇒ Object (readonly)
Returns the value of attribute raw_args.
27 28 29 |
# File 'lib/mps/elements/element.rb', line 27 def raw_args @raw_args end |
Class Method Details
.split_args(raw) ⇒ Object
Parses “work, release, status: done” → { attrs: { status: “done” }, tags: [“work”, “release”] } Parts containing “:” become named attrs; bare words become tags.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/mps/elements/element.rb', line 9 def self.split_args(raw) return { attrs: {}, tags: [] } if raw.nil? || raw.strip.empty? attrs = {} = [] raw.split(",").each do |part| part = part.strip next if part.empty? if part.include?(":") k, v = part.split(":", 2).map(&:strip) attrs[k.to_sym] = v else << part end end { attrs: attrs, tags: } end |
Instance Method Details
#display_str(padding_size = @refs.size - 1) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/mps/elements/element.rb', line 41 def display_str(padding_size = @refs.size - 1) strs = @body_str.strip.lines.map(&:strip) header = strs.first res_strs = [(PADDING * padding_size) + header] strs[1..].each { |str| res_strs << (PADDING * padding_size) + str } res_strs.join("\n") end |
#initialize(args:, refs:, body_str:) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/mps/elements/element.rb', line 29 def initialize(args:, refs:, body_str:) @raw_args = args.to_s @refs = refs @body_str = body_str @ref = refs.map(&:to_s).join(".") @parsed_args = self.class.respond_to?(:parse_args) ? self.class.parse_args(@raw_args) : {} end |
#tags ⇒ Object
37 38 39 |
# File 'lib/mps/elements/element.rb', line 37 def @parsed_args.fetch(:tags, []) end |