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
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
-
#body_str ⇒ Object
readonly
Returns the value of attribute body_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
-
.included(base) ⇒ Object
Called when Element is included in a class.
-
.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
Instance Attribute Details
#body_str ⇒ Object (readonly)
Returns the value of attribute body_str.
65 66 67 |
# File 'lib/mps/elements/element.rb', line 65 def body_str @body_str end |
#parsed_args ⇒ Object (readonly)
Returns the value of attribute parsed_args.
65 66 67 |
# File 'lib/mps/elements/element.rb', line 65 def parsed_args @parsed_args end |
#raw_args ⇒ Object (readonly)
Returns the value of attribute raw_args.
65 66 67 |
# File 'lib/mps/elements/element.rb', line 65 def raw_args @raw_args end |
Class Method Details
.included(base) ⇒ Object
Called when Element is included in a class. Extends the class with ClassMethods, enabling the ‘attribute` schema DSL.
7 8 9 |
# File 'lib/mps/elements/element.rb', line 7 def self.included(base) base.extend(ClassMethods) end |
.split_args(raw) ⇒ Object
Parses “work, release, status: done” → { attrs: { status: “done” }, tags: [“work”, “release”] } Parts containing “:” become named attrs; bare words become tags.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/mps/elements/element.rb', line 48 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
#initialize(args:, refs:, body_str:) ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/mps/elements/element.rb', line 67 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
75 76 77 |
# File 'lib/mps/elements/element.rb', line 75 def @parsed_args.fetch(:tags, []) end |