module Ravelry::Build
Utility module that takes the JSON response from the API call and creates the appropriate objects.
Public Class Methods
Creates and returns an array of {Ravelry::Category} objects.
See {Ravelry::Category} for more information.
# 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
Creates and returns a {Ravelry::Craft} object.
See {Ravelry::Craft} for more information.
# 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
Creates and returns an array of {Ravelry::Needle} objects.
There is more than one API endpoint for Needles
. This may not be the one you are looking for.
See {Ravelry::Needle} for more information.
# 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
Creates and returns an array of {Ravelry::Pack} objects.
See {Ravelry::Pack} for more information.
# 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
Creates and returns a {Ravelry::PatternType} object.
This is not the same as a PatternCategory object.
See {Ravelry::PatternType} for more information.
# 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
Creates and returns an array of {Ravelry::Photo} objects.
See {Ravelry::Photo} for more information.
# 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
Creates and returns an array of {Ravelry::Printing} objects.
See {Ravelry::Printing} for more information.
# 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
Creates and returns an array of {Ravelry::UserSite} objects.
See {Ravelry::UserSite} for more information.
# 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
Creates and returns an array of {Ravelry::YarnWeight} objects.
See {Ravelry::YarnWeight} for more information.
# 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
Creates and returns an array of {Ravelry::Yarn} objects.
See {Ravelry::Yarn} for more information.
# File lib/ravelry/utils/build.rb, line 115 def self.yarns(data) packs = data.fetch(:packs, []).select { |pack| pack[:yarn] } @yarns = packs.map do |pack| yarn = Yarn.new yarn.data = pack[:yarn] yarn end end