Class: Boom::Item
- Inherits:
-
Object
- Object
- Boom::Item
- Defined in:
- lib/kaboom/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 returns 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.
26 27 28 29 |
# File 'lib/kaboom/item.rb', line 26 def initialize(name,value) @name = name @value = value end |
Instance Attribute Details
#name ⇒ Object
Public: the String name of the Item
11 12 13 |
# File 'lib/kaboom/item.rb', line 11 def name @name end |
#value ⇒ Object
Public: the String value of the Item
14 15 16 |
# File 'lib/kaboom/item.rb', line 14 def value @value end |
Instance Method Details
#short_name ⇒ Object
45 46 47 |
# File 'lib/kaboom/item.rb', line 45 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.
52 53 54 |
# File 'lib/kaboom/item.rb', line 52 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.
67 68 69 |
# File 'lib/kaboom/item.rb', line 67 def to_hash { @name => @value } end |
#url ⇒ Object
Public: only return url part of value - if no url has been detected returns value.
Returns a String which preferably is a URL.
60 61 62 |
# File 'lib/kaboom/item.rb', line 60 def url @url ||= value.split(/\s+/).detect { |v| v =~ %r{\A[a-z0-9]+:\S+}i } || value end |