lib/boom/item.rb in boom-0.0.5 vs lib/boom/item.rb in boom-0.0.6

- old
+ new

@@ -16,15 +16,40 @@ # name - the String name of the Item # value - the String value of the Item # # Examples # - # Item.new("github", "http://github.com") + # Item.new("github", "https://github.com") # # Returns the newly initialized Item. def initialize(name,value) @name = name @value = value + end + + # 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. + def short_name + name.length > 15 ? "#{name[0..14]}…" : name[0..14] + end + + # Public: the amount of consistent spaces to pad based on Item#short_name. + # + # Returns a String of spaces. + def spacer + name.length > 15 ? '' : ' '*(15-name.length+1) end # Public: creates a Hash for this Item. # # Returns a Hash of its data.