Class: Kickstapi::ProjectMapper
- Inherits:
-
Object
- Object
- Kickstapi::ProjectMapper
- Defined in:
- lib/kickstapi/project_mapper.rb
Instance Attribute Summary collapse
-
#gateway ⇒ Object
readonly
Returns the value of attribute gateway.
Instance Method Summary collapse
-
#initialize(gateway) ⇒ ProjectMapper
constructor
A new instance of ProjectMapper.
- #load(project) ⇒ Object
- #project_by_url(url) ⇒ Object
- #projects_by_filter(filter, max_results = :all) ⇒ Object
- #projects_by_username(username) ⇒ Object
Constructor Details
#initialize(gateway) ⇒ ProjectMapper
Returns a new instance of ProjectMapper.
7 8 9 |
# File 'lib/kickstapi/project_mapper.rb', line 7 def initialize(gateway) @gateway = gateway end |
Instance Attribute Details
#gateway ⇒ Object (readonly)
Returns the value of attribute gateway.
5 6 7 |
# File 'lib/kickstapi/project_mapper.rb', line 5 def gateway @gateway end |
Instance Method Details
#load(project) ⇒ Object
58 59 60 |
# File 'lib/kickstapi/project_mapper.rb', line 58 def load(project) fill_project(project, @gateway.project_by_url(project.url)) end |
#project_by_url(url) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/kickstapi/project_mapper.rb', line 36 def project_by_url(url) project_hash = @gateway.project_by_url(url) project = Project.new(data_source: self) project.url = project_hash[:url] fill_project(project, project_hash) project end |
#projects_by_filter(filter, max_results = :all) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/kickstapi/project_mapper.rb', line 11 def projects_by_filter(filter, max_results = :all) page = 1 should_page = true projects = [] loop do break unless should_page break unless max_results == :all || max_results.to_i >= projects.size projects_hashes, should_page = @gateway.projects_with_name(filter, page) page += 1 projects_hashes.each do |project_hash| project = Project.new(data_source: self) project.complete(project_hash) projects << project end end projects = projects[0...max_results] unless max_results == :all projects end |
#projects_by_username(username) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/kickstapi/project_mapper.rb', line 45 def projects_by_username(username) projects = [] project_hashes = @gateway.projects_by_username username project_hashes.each do |project_hash| project = Project.new(data_source: self) project.complete(project_hash) projects << project end projects end |