Module: Ravelry::Build
- Included in:
- Pattern
- Defined in:
- lib/ravelry/utils/build.rb
Overview
Utility module that takes the JSON response from the API call and creates the appropriate objects.
Class Method Summary collapse
-
.author(data) ⇒ Object
Creates and returns a Author object.
-
.categories(data) ⇒ Object
Creates and returns an array of Category objects.
-
.craft(data) ⇒ Object
Creates and returns a Craft object.
-
.needles(data) ⇒ Object
Creates and returns an array of Needle objects.
-
.packs(data) ⇒ Object
Creates and returns an array of Pack objects.
-
.pattern_type(data) ⇒ Object
Creates and returns a PatternType object.
-
.photos(data) ⇒ Object
Creates and returns an array of Photo objects.
-
.printings(data) ⇒ Object
Creates and returns an array of Printing objects.
-
.user_sites(data) ⇒ Object
Creates and returns an array of UserSite objects.
-
.yarn_weights(data) ⇒ Object
Creates and returns an array of YarnWeight objects.
-
.yarns(data) ⇒ Object
Creates and returns an array of Yarn objects.
Class Method Details
.author(data) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/ravelry/utils/build.rb', line 11 def self.(data) if data[:pattern_author] @author = Author.new(data[:pattern_author]) else @author = nil end end |
.categories(data) ⇒ Object
23 24 25 26 27 |
# File 'lib/ravelry/utils/build.rb', line 23 def self.categories(data) @categories = data.fetch(:pattern_categories, []).map do |cat| Category.new(cat) end end |
.craft(data) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/ravelry/utils/build.rb', line 33 def self.craft(data) if data[:craft] @craft = Craft.new(data[:craft]) else @craft = nil end end |
.needles(data) ⇒ Object
47 48 49 50 51 |
# File 'lib/ravelry/utils/build.rb', line 47 def self.needles(data) @needles = data.fetch(:pattern_needle_sizes, []).map do |ndl| Needle.new(ndl) end end |
.packs(data) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/ravelry/utils/build.rb', line 57 def self.packs(data) @packs = data.fetch(:packs, []).map do |pack_data| pack = Pack.new pack.data = pack_data pack end end |
.pattern_type(data) ⇒ Object
Creates and returns a PatternType object.
This is not the same as a PatternCategory object.
See PatternType for more information.
71 72 73 74 75 76 77 |
# File 'lib/ravelry/utils/build.rb', line 71 def self.pattern_type(data) if data[:pattern_type] @pattern_type = PatternType.new(data[:pattern_type]) else @pattern_type = nil end end |
.photos(data) ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/ravelry/utils/build.rb', line 83 def self.photos(data) @photos = data.fetch(:photos, []).map do |photo_data| photo = Photo.new(photo_data[:id]) photo.data = photo_data photo end end |
.printings(data) ⇒ Object
95 96 97 98 99 |
# File 'lib/ravelry/utils/build.rb', line 95 def self.printings(data) @printings = data.fetch(:printings, []).map do |printing_data| Printing.new(printing_data) end end |
.user_sites(data) ⇒ Object
105 106 107 108 109 |
# File 'lib/ravelry/utils/build.rb', line 105 def self.user_sites(data) @user_sites = data.fetch(:user_sites, []).map do |site| UserSite.new(site) end end |
.yarn_weights(data) ⇒ Object
Creates and returns an array of YarnWeight objects.
See YarnWeight for more information.
129 130 131 132 133 134 135 136 137 |
# File 'lib/ravelry/utils/build.rb', line 129 def self.yarn_weights(data) packs = data.fetch(:packs, []).select { |pack| pack[:yarn_weight] } @yarn_weights = packs.map do |pack| yarn_weight = YarnWeight.new yarn_weight.data = pack[:yarn_weight] yarn_weight end end |