Class: Bettery::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/bettery/project.rb

Constant Summary collapse

REGEXP =
/\Ahttps?.+\/projects\/(?<id>\d+).*\z/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project) ⇒ Project

Returns a new instance of Project.



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/bettery/project.rb', line 6

def initialize(project)
  case project
  when Integer
    @id = project
  when String
    @id = extract_id_from_url(project)
  when Project
    @id = project.id
  when Hash
    @id = project[:id]
  end
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



3
4
5
# File 'lib/bettery/project.rb', line 3

def id
  @id
end

Class Method Details

.path(project) ⇒ String

Get the api path for a project

Parameters:

  • project (Integer, String, Hash, Project)

    A Betterplace project.

Returns:

  • (String)

    Api path.



27
28
29
# File 'lib/bettery/project.rb', line 27

def self.path project
  new(project).path
end

Instance Method Details

#pathString

Returns Project API path.

Returns:

  • (String)

    Project API path



20
21
22
# File 'lib/bettery/project.rb', line 20

def path
  "projects/#{id}.json"
end

#urlString

Project URL based on Client#api_endpoint

Returns:

  • (String)


33
34
35
# File 'lib/bettery/project.rb', line 33

def url
  File.join(Bettery.api_endpoint, path)
end