Class: Pv::Story

Inherits:
Object show all
Defined in:
lib/pv/story.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(from_pivotal_story) ⇒ Story

Returns a new instance of Story.



9
10
11
12
13
14
# File 'lib/pv/story.rb', line 9

def initialize from_pivotal_story
  @pivotal_story = from_pivotal_story
  %w(id story_type requested_by owned_by current_state name description estimate).each do |attr|
    self.send "#{attr}=", from_pivotal_story.send(attr)
  end
end

Instance Attribute Details

#current_stateObject

Returns the value of attribute current_state.



5
6
7
# File 'lib/pv/story.rb', line 5

def current_state
  @current_state
end

#descriptionObject

Returns the value of attribute description.



5
6
7
# File 'lib/pv/story.rb', line 5

def description
  @description
end

#estimateObject

Returns the value of attribute estimate.



5
6
7
# File 'lib/pv/story.rb', line 5

def estimate
  @estimate
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/pv/story.rb', line 5

def id
  @id
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/pv/story.rb', line 5

def name
  @name
end

#owned_byObject

Returns the value of attribute owned_by.



5
6
7
# File 'lib/pv/story.rb', line 5

def owned_by
  @owned_by
end

#pivotal_storyObject (readonly)

Returns the value of attribute pivotal_story.



7
8
9
# File 'lib/pv/story.rb', line 7

def pivotal_story
  @pivotal_story
end

#requested_byObject

Returns the value of attribute requested_by.



5
6
7
# File 'lib/pv/story.rb', line 5

def requested_by
  @requested_by
end

#story_typeObject

Returns the value of attribute story_type.



5
6
7
# File 'lib/pv/story.rb', line 5

def story_type
  @story_type
end

Class Method Details

.create(from_attributes = {}) ⇒ Object

Build a new Pivotal story with the given attributes.



22
23
24
# File 'lib/pv/story.rb', line 22

def self.create from_attributes={}
  new Pv.tracker.project.stories.create from_attributes
end

.find(by_id) ⇒ Object

Find a story by its Pivotal ID



17
18
19
# File 'lib/pv/story.rb', line 17

def self.find by_id
  new Pv.tracker.stories.select { |s| s.id == by_id.to_i }.first
end

Instance Method Details

#errorsObject

Show all errors related to this story.



60
61
62
# File 'lib/pv/story.rb', line 60

def errors
  @pivotal_story.errors
end

#in_progress?Boolean

This story is “in progress” if its code has not left the dev machine, or is on stage and hasn’t been pushed to production yet.

Returns:

  • (Boolean)


36
37
38
39
40
41
42
# File 'lib/pv/story.rb', line 36

def in_progress?
  if current_state =~ /\A(started|finished)\Z/
    true
  else
    false
  end
end

#renderObject

Render this Story in plain text.



27
28
29
30
31
# File 'lib/pv/story.rb', line 27

def render
  source = IO.read "#{Pv.root}/lib/templates/story.txt.erb"
  template = ERB.new(source)
  template.result(binding)
end

#saved?Boolean

Test if this story has been saved on Pivotal.

Returns:

  • (Boolean)


50
51
52
# File 'lib/pv/story.rb', line 50

def saved?
  Pv.tracker.project.stories.find(id).present?
end

#update(status) ⇒ Object

Update the current status of a Story.



45
46
47
# File 'lib/pv/story.rb', line 45

def update(status)
  @pivotal_story.update(current_state: status)
end

#valid?Boolean

Test if this story has any errors.

Returns:

  • (Boolean)


55
56
57
# File 'lib/pv/story.rb', line 55

def valid?
  errors.any?
end