Class: Yapt::Story

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_story) ⇒ Story

Returns a new instance of Story.



62
63
64
# File 'lib/yapt/story.rb', line 62

def initialize(raw_story)
  @raw_story = raw_story
end

Instance Attribute Details

#raw_storyObject (readonly)

Returns the value of attribute raw_story.



61
62
63
# File 'lib/yapt/story.rb', line 61

def raw_story
  @raw_story
end

Class Method Details

.base_site_urlObject



57
58
59
# File 'lib/yapt/story.rb', line 57

def self.base_site_url
  "https://www.pivotaltracker.com/projects/#{Yapt.project_id}"
end

.bottom_of_backlogObject



37
38
39
# File 'lib/yapt/story.rb', line 37

def self.bottom_of_backlog
  find(["state:unstarted"]).last
end

.bottom_of_iceboxObject



41
42
43
# File 'lib/yapt/story.rb', line 41

def self.bottom_of_icebox
  find(["state:unscheduled"]).last
end

.find(options = ["limit=5"]) ⇒ Object



3
4
5
6
7
8
# File 'lib/yapt/story.rb', line 3

def self.find(options = ["limit=5"])
  return find_one(options) if options.kind_of?(String)
  params = Filter.parse(options)
  results = Request.new("stories", params, :get).result
  results.collect {|r| new(r) }
end

.find_by_id(id) ⇒ Object



25
26
27
# File 'lib/yapt/story.rb', line 25

def self.find_by_id(id)
  new(Request.new("stories/#{id}", {}, :get).result)
end

.find_one(id) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/yapt/story.rb', line 10

def self.find_one(id)
  case id
  when /\A\d+\Z/  then find_by_id(id)
  when 'tback'    then top_of_backlog
  when 'tbacklog' then top_of_backlog
  when 'tice'     then top_of_icebox
  when 'ticebox'  then top_of_icebox

  when 'bback'    then bottom_of_backlog
  when 'bbacklog' then bottom_of_backlog
  when 'bice'     then bottom_of_icebox
  when 'bicebox'  then bottom_of_icebox
  end
end

.images_url(id) ⇒ Object



53
54
55
# File 'lib/yapt/story.rb', line 53

def self.images_url(id)
  "#{just_url(id)}/images"
end

.just_url(id) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/yapt/story.rb', line 45

def self.just_url(id)
  if id
    "#{base_site_url}/stories/#{id}"
  else
    base_site_url
  end
end

.top_of_backlogObject



29
30
31
# File 'lib/yapt/story.rb', line 29

def self.top_of_backlog
  find(["state:unstarted", "limit:1"]).first
end

.top_of_iceboxObject



33
34
35
# File 'lib/yapt/story.rb', line 33

def self.top_of_icebox
  find(["state:unscheduled", "limit:1"]).first
end

Instance Method Details

#commentsObject



78
79
80
# File 'lib/yapt/story.rb', line 78

def comments
  @comments ||= Comment.find(id)
end

#created_at_displayObject



94
95
96
# File 'lib/yapt/story.rb', line 94

def created_at_display
  "Created: #{time_display(created_at)}"
end

#has_image?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/yapt/story.rb', line 74

def has_image?
  Request.new("stories/", {filter: "id:#{id} has:attachment"}, :get).result.any?
end

#owner_initialsObject



82
83
84
85
86
87
88
# File 'lib/yapt/story.rb', line 82

def owner_initials
  if owned_by_id
    "Owner: #{Member.find(owned_by_id).initials}"
  else
    "No owner"
  end
end

#requester_initialsObject



90
91
92
# File 'lib/yapt/story.rb', line 90

def requester_initials
  "Requester: #{Member.find(requested_by_id).initials}"
end

#time_display(time) ⇒ Object



102
103
104
# File 'lib/yapt/story.rb', line 102

def time_display(time)
  Time.parse(time).strftime("%a %d%b %I:%M")
end

#updated_at_displayObject



98
99
100
# File 'lib/yapt/story.rb', line 98

def updated_at_display
  "Updated: #{time_display(updated_at)}"
end