Class: Boom::Item

Inherits:
Object
  • Object
show all
Defined in:
lib/boom/item.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#nameObject

Public: the String name of the Item



10
11
12
# File 'lib/boom/item.rb', line 10

def name
  @name
end

#valueObject

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_nameObject

Public: the shortened String name of the Item. Truncates with ellipses if larger.

Examples

item = Item.new("github's home page","https://github.com")
item.short_name
# => 'github's home p…'

item = Item.new("github","https://github.com")
item.short_name
# => 'github'

Returns the shortened name.



44
45
46
# File 'lib/boom/item.rb', line 44

def short_name
  name.length > 15 ? "#{name[0..14]}" : name[0..14]
end

#spacerObject

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_hashObject

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

#urlObject

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