Class: Sly::Item

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#archivedObject

Returns the value of attribute archived.



9
10
11
# File 'lib/sly/item.rb', line 9

def archived
  @archived
end

#assigned_toObject

Returns the value of attribute assigned_to.



9
10
11
# File 'lib/sly/item.rb', line 9

def assigned_to
  @assigned_to
end

#numberObject

Returns the value of attribute number.



9
10
11
# File 'lib/sly/item.rb', line 9

def number
  @number
end

#scoreObject

Returns the value of attribute score.



9
10
11
# File 'lib/sly/item.rb', line 9

def score
  @score
end

#statusObject

Returns the value of attribute status.



9
10
11
# File 'lib/sly/item.rb', line 9

def status
  @status
end

#tagsObject

Returns the value of attribute tags.



9
10
11
# File 'lib/sly/item.rb', line 9

def tags
  @tags
end

#titleObject

Returns the value of attribute title.



9
10
11
# File 'lib/sly/item.rb', line 9

def title
  @title
end

#typeObject

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_slugObject



61
62
63
# File 'lib/sly/item.rb', line 61

def git_slug
  "#{self.type}/" + self.slug.slice(0, 60) + "-#{self.number}"
end

#overviewObject 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


43
44
45
# File 'lib/sly/item.rb', line 43

def print
  $stdout.print self.overview
end

#slugObject



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