Class: Sly::Item
- Inherits:
-
Object
- Object
- Sly::Item
- Defined in:
- lib/sly/item.rb
Constant Summary collapse
- TYPE_COLOR =
{ task: :black, test: :blue, defect: :red, feature: :green }
- TYPES =
{ "task" => :task, "defect" => :defect, "story" => :feature, "test" => :test}
Instance Attribute Summary collapse
-
#archived ⇒ Object
Returns the value of attribute archived.
-
#assigned_to ⇒ Object
Returns the value of attribute assigned_to.
-
#number ⇒ Object
Returns the value of attribute number.
-
#score ⇒ Object
Returns the value of attribute score.
-
#status ⇒ Object
Returns the value of attribute status.
-
#tags ⇒ Object
Returns the value of attribute tags.
-
#title ⇒ Object
Returns the value of attribute title.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #assign(assigned_to) ⇒ Object
- #git_slug ⇒ Object
-
#initialize(item_attributes = {}) ⇒ Item
constructor
A new instance of Item.
- #overview ⇒ Object (also: #to_s)
- #prettify(content, wrap_limit) ⇒ Object
- #print ⇒ Object
- #slug ⇒ Object
Constructor Details
#initialize(item_attributes = {}) ⇒ Item
Returns a new instance of Item.
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/sly/item.rb', line 25 def initialize(item_attributes = {}) @number = item_attributes["number"] @archived = item_attributes["archived"] @title = item_attributes["title"] @score = item_attributes["score"] @tags = item_attributes["tags"] @status = item_attributes["status"] @type = TYPES[item_attributes["type"]].to_sym assign(item_attributes["assigned_to"]) end |
Instance Attribute Details
#archived ⇒ Object
Returns the value of attribute archived.
9 10 11 |
# File 'lib/sly/item.rb', line 9 def archived @archived end |
#assigned_to ⇒ Object
Returns the value of attribute assigned_to.
9 10 11 |
# File 'lib/sly/item.rb', line 9 def assigned_to @assigned_to end |
#number ⇒ Object
Returns the value of attribute number.
9 10 11 |
# File 'lib/sly/item.rb', line 9 def number @number end |
#score ⇒ Object
Returns the value of attribute score.
9 10 11 |
# File 'lib/sly/item.rb', line 9 def score @score end |
#status ⇒ Object
Returns the value of attribute status.
9 10 11 |
# File 'lib/sly/item.rb', line 9 def status @status end |
#tags ⇒ Object
Returns the value of attribute tags.
9 10 11 |
# File 'lib/sly/item.rb', line 9 def @tags end |
#title ⇒ Object
Returns the value of attribute title.
9 10 11 |
# File 'lib/sly/item.rb', line 9 def title @title end |
#type ⇒ Object
Returns the value of attribute type.
9 10 11 |
# File 'lib/sly/item.rb', line 9 def type @type end |
Class Method Details
.with_number(number) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/sly/item.rb', line 11 def self.with_number(number) begin items = YAML::load(File.open(File.join(".sly", "items"))) rescue Exception => e raise "Unable to locate project files" end if items items.values.flatten.select { |i| i.number.to_s == number.to_s }.first else nil end end |
Instance Method Details
#assign(assigned_to) ⇒ Object
65 66 67 68 |
# File 'lib/sly/item.rb', line 65 def assign(assigned_to) @assigned_to = assigned_to ? "#{assigned_to["first_name"]} #{assigned_to["last_name"][0]}." : "Unassigned" end |
#git_slug ⇒ Object
61 62 63 |
# File 'lib/sly/item.rb', line 61 def git_slug "#{self.type}/" + self.slug.slice(0, 60) + "-#{self.number}" end |
#overview ⇒ Object Also known as: to_s
36 37 38 39 |
# File 'lib/sly/item.rb', line 36 def overview quick_ref = "##{@number} - ".color(type_colour) + " #{@score} ".background(type_colour).color(:white) + " #{@assigned_to} ".color(type_colour) self.prettify([quick_ref, @title.color(type_colour)].join("\n"), 64)+"\n" end |
#prettify(content, wrap_limit) ⇒ Object
47 48 49 |
# File 'lib/sly/item.rb', line 47 def prettify(content, wrap_limit) content.scan(/\S.{0,#{wrap_limit}}\S(?=\s|$)|\S+/).join("\n") end |
#print ⇒ Object
43 44 45 |
# File 'lib/sly/item.rb', line 43 def print $stdout.print self.overview end |
#slug ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/sly/item.rb', line 51 def slug if self.type == :feature slug_string = self.title.downcase.match(/(as a.*i want.*) so that.*/)[1] else slug_string = self.title.downcase end slug_string.gsub(/(&|&)/, 'and').gsub(/ to | the |\s+|_+|\//, '-').gsub(/[^\w-]/, '').squeeze('-') end |