Class: Boom::Item
- Inherits:
-
Object
- Object
- Boom::Item
- Defined in:
- lib/boom/item.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Public: the String name of the Item.
-
#value ⇒ Object
Public: the String value of the Item.
Instance Method Summary collapse
-
#initialize(name, value) ⇒ Item
constructor
Public: creates a new Item object.
-
#short_name ⇒ Object
Public: the shortened String name of the Item.
-
#spacer ⇒ Object
Public: the amount of consistent spaces to pad based on Item#short_name.
-
#to_hash ⇒ Object
Public: creates a Hash for this Item.
-
#url ⇒ Object
Public: only return url part of value - if no url has been detected it’ll return the value.
Constructor Details
#initialize(name, value) ⇒ Item
Public: creates a new Item object.
name - the String name of the Item value - the String value of the Item
Examples
Item.new("github", "https://github.com")
Returns the newly initialized Item.
25 26 27 28 |
# File 'lib/boom/item.rb', line 25 def initialize(name,value) @name = name @value = value end |
Instance Attribute Details
#name ⇒ Object
Public: the String name of the Item
10 11 12 |
# File 'lib/boom/item.rb', line 10 def name @name end |
#value ⇒ Object
Public: the String value of the Item
13 14 15 |
# File 'lib/boom/item.rb', line 13 def value @value end |
Instance Method Details
#short_name ⇒ Object
44 45 46 |
# File 'lib/boom/item.rb', line 44 def short_name name.length > 15 ? "#{name[0..14]}…" : name[0..14] end |
#spacer ⇒ Object
Public: the amount of consistent spaces to pad based on Item#short_name.
Returns a String of spaces.
51 52 53 |
# File 'lib/boom/item.rb', line 51 def spacer name.length > 15 ? '' : ' '*(15-name.length+1) end |
#to_hash ⇒ Object
Public: creates a Hash for this Item.
Returns a Hash of its data.
66 67 68 |
# File 'lib/boom/item.rb', line 66 def to_hash { @name => @value } end |
#url ⇒ Object
Public: only return url part of value - if no url has been detected it’ll return the value.
Returns a String which preferably is a URL.
59 60 61 |
# File 'lib/boom/item.rb', line 59 def url @url ||= value.split(/\s+/).detect { |v| v =~ %r{\A[a-z0-9]+:\S+}i } || value end |