Class: Boom::Item

Inherits:
Object
  • Object
show all
Defined in:
lib/kaboom/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.



26
27
28
29
# File 'lib/kaboom/item.rb', line 26

def initialize(name,value)
  @name = name
  @value = value
end

Instance Attribute Details

#nameObject

Public: the String name of the Item



11
12
13
# File 'lib/kaboom/item.rb', line 11

def name
  @name
end

#valueObject

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_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.



45
46
47
# File 'lib/kaboom/item.rb', line 45

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.



52
53
54
# File 'lib/kaboom/item.rb', line 52

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.



67
68
69
# File 'lib/kaboom/item.rb', line 67

def to_hash
  { @name => @value }
end

#urlObject

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