Class: MicroMicro::Property
- Inherits:
-
Object
- Object
- MicroMicro::Property
- Defined in:
- lib/micro_micro/property.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#collection ⇒ MicroMicro::PropertiesCollection
The PropertiesCollection to which this Property belongs.
-
#name ⇒ String
readonly
This Property‘s
name
value. -
#node ⇒ Nokogiri::XML::Element
readonly
This Property‘s node.
-
#prefix ⇒ String
readonly
This Property‘s
prefix
value.
Class Method Summary collapse
-
.from_context(context) ⇒ Array<MicroMicro::Property>
Extract Propertys from a context.
Instance Method Summary collapse
-
#date_time_property? ⇒ Boolean
Is this Property a datetime property?.
-
#embedded_markup_property? ⇒ Boolean
Is this Property an embedded markup property?.
-
#implied? ⇒ Boolean
Always return
false
when asked if this Property is an implied property. -
#initialize(node, token) ⇒ Property
constructor
Parse a node for property data.
-
#inspect ⇒ String
:nocov:.
- #item ⇒ MicroMicro::Item?
- #item_node? ⇒ Boolean
-
#plain_text_property? ⇒ Boolean
Is this Property a plain text property?.
-
#url_property? ⇒ Boolean
Is this Property a url property?.
-
#value ⇒ String, Hash
Return this Property‘s parsed value.
-
#value? ⇒ Boolean
Returns
true
if this Property‘svalue
is anything other than blank ornil
.
Constructor Details
#initialize(node, token) ⇒ Property
Parse a node for property data.
75 76 77 78 |
# File 'lib/micro_micro/property.rb', line 75 def initialize(node, token) @node = node @prefix, @name = token.split("-", 2) end |
Instance Attribute Details
#collection ⇒ MicroMicro::PropertiesCollection
The MicroMicro::PropertiesCollection to which this MicroMicro::Property belongs.
40 41 42 |
# File 'lib/micro_micro/property.rb', line 40 def collection @collection end |
#name ⇒ String (readonly)
This MicroMicro::Property‘s name
value.
45 46 47 |
# File 'lib/micro_micro/property.rb', line 45 def name @name end |
#node ⇒ Nokogiri::XML::Element (readonly)
This MicroMicro::Property‘s node.
50 51 52 |
# File 'lib/micro_micro/property.rb', line 50 def node @node end |
#prefix ⇒ String (readonly)
This MicroMicro::Property‘s prefix
value.
55 56 57 |
# File 'lib/micro_micro/property.rb', line 55 def prefix @prefix end |
Class Method Details
.from_context(context) ⇒ Array<MicroMicro::Property>
Extract MicroMicro::Propertys from a context.
61 62 63 64 65 66 67 68 |
# File 'lib/micro_micro/property.rb', line 61 def self.from_context(context) PropertyNodeSearch .new(context.document) .search(context) .flat_map do |node| Helpers.property_class_names_from(node).map { |token| new(node, token) } end end |
Instance Method Details
#date_time_property? ⇒ Boolean
Is this MicroMicro::Property a datetime property?
83 84 85 |
# File 'lib/micro_micro/property.rb', line 83 def date_time_property? prefix == "dt" end |
#embedded_markup_property? ⇒ Boolean
Is this MicroMicro::Property an embedded markup property?
90 91 92 |
# File 'lib/micro_micro/property.rb', line 90 def prefix == "e" end |
#implied? ⇒ Boolean
Always return false
when asked if this MicroMicro::Property is an implied property.
100 101 102 |
# File 'lib/micro_micro/property.rb', line 100 def implied? false end |
#inspect ⇒ String
:nocov:
107 108 109 110 111 112 |
# File 'lib/micro_micro/property.rb', line 107 def inspect "#<#{self.class}:#{format("%#0x", object_id)} " \ "name: #{name.inspect}, " \ "prefix: #{prefix.inspect}, " \ "value: #{value.inspect}>" end |
#item ⇒ MicroMicro::Item?
Parse this MicroMicro::Property‘s node as a Item, if applicable.
119 120 121 |
# File 'lib/micro_micro/property.rb', line 119 def item @item ||= Item.new(node) if item_node? end |
#item_node? ⇒ Boolean
Should this MicroMicro::Property‘s node be parsed as a Item?
129 130 131 |
# File 'lib/micro_micro/property.rb', line 129 def item_node? @item_node ||= Helpers.item_node?(node) end |
#plain_text_property? ⇒ Boolean
Is this MicroMicro::Property a plain text property?
136 137 138 |
# File 'lib/micro_micro/property.rb', line 136 def plain_text_property? prefix == "p" end |
#url_property? ⇒ Boolean
Is this MicroMicro::Property a url property?
143 144 145 |
# File 'lib/micro_micro/property.rb', line 143 def url_property? prefix == "u" end |
#value ⇒ String, Hash
Return this MicroMicro::Property‘s parsed value.
rubocop:disable Metrics
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/micro_micro/property.rb', line 152 def value @value ||= if item_node? hash = item.to_h return hash.merge(parser.value) if p_property = item.properties.find_by(name: "name") if plain_text_property? u_property = item.properties.find_by(name: "url") if url_property? hash.merge(value: (p_property || u_property || parser).value) else parser.value end end |
#value? ⇒ Boolean
Returns true
if this MicroMicro::Property‘s value
is anything other than blank or nil
.
173 174 175 |
# File 'lib/micro_micro/property.rb', line 173 def value? value.present? end |