ravelry 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +15 -8
- data/VERSION +1 -1
- data/lib/ravelry.rb +3 -1
- data/lib/ravelry/misc.rb +10 -8
- data/lib/ravelry/needle.rb +74 -0
- data/lib/ravelry/needles.rb +35 -0
- data/lib/ravelry/pattern.rb +6 -6
- data/lib/ravelry/utils/build.rb +3 -3
- data/lib/ravelry/utils/request.rb +14 -0
- data/lib/ravelry/version.rb +1 -1
- data/spec/ravelry/{pattern_needle_spec.rb → needle_spec.rb} +4 -12
- data/spec/ravelry/needles_spec.rb +24 -0
- data/spec/ravelry/utils/build_spec.rb +1 -1
- metadata +10 -5
- data/lib/ravelry/pattern_needle.rb +0 -54
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 069008bb3012510d0c56139996efd09180c18c35
|
4
|
+
data.tar.gz: da328e573a10420115bb936ca902b68c54ddcc60
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b0ef35f8f4eeebcf3994cab99ee7a56acc01053a84b16707ffe3aec8ab398b19782f1a6c6182b4f77c010307a5126acc98e20f471afb90a7f918934be01279d
|
7
|
+
data.tar.gz: 2aa97bb1a10842a9aec7d41bd5c500a0379c5ed81a1bfac16fd907b69891151a75e00d7411ffac21ffe1f6cf5069f98fc9a92f3923d1d4e33b6c18dbb8b9a62f
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# Ravelry
|
2
2
|
|
3
|
-
_You are reading documentation for version: 0.0.
|
3
|
+
_You are reading documentation for version: 0.0.6_
|
4
4
|
|
5
|
-
[ ](https://codeship.com/projects/109462)
|
6
6
|
|
7
7
|
This gem is actively being developed. Be sure to check the branch for the version you're using as breaking changes can (and will!) be introduced.
|
8
8
|
|
@@ -14,10 +14,17 @@ Ravelry API documentation is currently available [here](http://www.ravelry.com/a
|
|
14
14
|
|
15
15
|
## API coverage
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
See documentation for each class (or module) to see how to initialize the objects.
|
18
|
+
|
19
|
+
API | Endpoint | Ravelry gem class / module
|
20
|
+
----|----------|------------------
|
21
|
+
**Misc** | [color_families](http://www.ravelry.com/api#/_color_families) | `Ravelry::Misc.color_families`
|
22
|
+
**Misc** | [yarn_weights](http://www.ravelry.com/api#/_yarn_weights) | `Ravelry::Misc.yarn_weights`
|
23
|
+
**Needles** | [list](http://www.ravelry.com/api#needles_list) | `Ravelry::Needles.list`
|
24
|
+
**Needles** | [sizes](http://www.ravelry.com/api#needles_sizes) | `Ravelry::Needles.sizes`
|
25
|
+
**Needles** | [types](http://www.ravelry.com/api#needles_types) | `Ravelry::Needles.types`
|
26
|
+
**Patterns** | [show](http://www.ravelry.com/api#patterns_show) | `Ravelry::Pattern.get`
|
27
|
+
**People** | [show](http://www.ravelry.com/api#people_show) | `Ravelry::User.get`
|
21
28
|
|
22
29
|
# Installation
|
23
30
|
|
@@ -32,7 +39,7 @@ Hooray! You now have a gem.
|
|
32
39
|
Add to your `Gemfile`:
|
33
40
|
|
34
41
|
```ruby
|
35
|
-
gem "ravelry", "~> 0.0.
|
42
|
+
gem "ravelry", "~> 0.0.6"
|
36
43
|
```
|
37
44
|
|
38
45
|
**I highly recommend pinning your version** because the gem is in active development and I _promise_ I will break shit.
|
@@ -67,7 +74,7 @@ Ravelry.configuration.personal_key
|
|
67
74
|
|
68
75
|
# Usage
|
69
76
|
|
70
|
-
Full documentation for this gem is available [here](http://www.rubydoc.info/gems/ravelry/0.0.
|
77
|
+
Full documentation for this gem is available [here](http://www.rubydoc.info/gems/ravelry/0.0.6).
|
71
78
|
|
72
79
|
# API quirks
|
73
80
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.6
|
data/lib/ravelry.rb
CHANGED
@@ -4,6 +4,7 @@ require 'typhoeus'
|
|
4
4
|
require 'ravelry/configuration'
|
5
5
|
|
6
6
|
require 'ravelry/utils/build'
|
7
|
+
require 'ravelry/utils/request'
|
7
8
|
require 'ravelry/utils/utilities'
|
8
9
|
|
9
10
|
require 'ravelry/author'
|
@@ -12,9 +13,10 @@ require 'ravelry/color_family'
|
|
12
13
|
require 'ravelry/craft'
|
13
14
|
require 'ravelry/data'
|
14
15
|
require 'ravelry/misc'
|
16
|
+
require 'ravelry/needle'
|
17
|
+
require 'ravelry/needles'
|
15
18
|
require 'ravelry/pack'
|
16
19
|
require 'ravelry/pattern'
|
17
|
-
require 'ravelry/pattern_needle'
|
18
20
|
require 'ravelry/pattern_type'
|
19
21
|
require 'ravelry/photo'
|
20
22
|
require 'ravelry/printing'
|
data/lib/ravelry/misc.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
module Ravelry
|
2
2
|
|
3
|
+
# Handles API request for the `Misc` endpoints. Always returns an array of objects.
|
4
|
+
#
|
3
5
|
module Misc
|
4
6
|
extend self
|
5
7
|
|
@@ -8,17 +10,17 @@ module Ravelry
|
|
8
10
|
# Returns an array of {Ravelry::ColorFamily} objects.
|
9
11
|
#
|
10
12
|
def color_families
|
11
|
-
|
12
|
-
result
|
13
|
-
@data = result[:color_families]
|
14
|
-
@data.map { |d| ColorFamily.new(d) }
|
13
|
+
result = Utils::Request.get("color_families.json", :color_families)
|
14
|
+
result.map { |color_family| ColorFamily.new(color_family) }
|
15
15
|
end
|
16
16
|
|
17
|
+
# Handles GET API call and parses JSON response for the `Misc#color_families` Ravelry endpoint.
|
18
|
+
#
|
19
|
+
# Returns an array of {Ravelry::ColorFamily} objects.
|
20
|
+
#
|
17
21
|
def yarn_weights
|
18
|
-
|
19
|
-
result
|
20
|
-
@data = result[:yarn_weights]
|
21
|
-
@data.map { |d| YarnWeight.new(d) }
|
22
|
+
result = Utils::Request.get("yarn_weights.json", :yarn_weights)
|
23
|
+
result.map { |yarn_weight| YarnWeight.new(yarn_weight) }
|
22
24
|
end
|
23
25
|
end
|
24
26
|
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module Ravelry
|
2
|
+
|
3
|
+
# The API endpoint for fetching `Needle` objects can be found in {Ravelry::Needles}.
|
4
|
+
#
|
5
|
+
# A `Needle` object can be created by several different endpoints but is currently only implemented in {Ravelry::Misc}.
|
6
|
+
#
|
7
|
+
class Needle
|
8
|
+
attr_reader :id, :metric, :metric_name, :hook, :name, :pretty_metric, :us, :description, :length, :needle_size_id, :type_name, :comment, :needle_type, :needle_type_id, :data
|
9
|
+
def initialize(data)
|
10
|
+
@data = data
|
11
|
+
@id = data[:id]
|
12
|
+
# Crochet hook size.
|
13
|
+
# Corresponding to this metric size, if one exists.
|
14
|
+
#
|
15
|
+
@hook = data[:hook]
|
16
|
+
# US size number corresponding to this metric size, if one exists
|
17
|
+
#
|
18
|
+
@us = data[:us]
|
19
|
+
# Combination of US and metric.
|
20
|
+
# Example: "US 4 - 3.5 mm"
|
21
|
+
#
|
22
|
+
@name = data[:name]
|
23
|
+
# Metric designation for hook size.
|
24
|
+
#
|
25
|
+
@metric = data[:metric]
|
26
|
+
# Metric size for knitting needles (Integer or Float).
|
27
|
+
#
|
28
|
+
@metric_name = data[:metric_name]
|
29
|
+
# Metric size for knitting needles (pretty format).
|
30
|
+
#
|
31
|
+
@pretty_metric = data[:pretty_metric]
|
32
|
+
|
33
|
+
@description = data[:description]
|
34
|
+
@length = data[:length]
|
35
|
+
@needle_size_id = data[:needle_size_id]
|
36
|
+
@type_name = data[:type_name]
|
37
|
+
@needle_type = data[:needle_type]
|
38
|
+
@needle_type_id = data[:needle_type_id]
|
39
|
+
@comment = data[:comment]
|
40
|
+
end
|
41
|
+
|
42
|
+
# Takes the US size and turns it into a string.
|
43
|
+
# Example: "US 4"
|
44
|
+
#
|
45
|
+
def us_string
|
46
|
+
"US #{@us}".strip
|
47
|
+
end
|
48
|
+
|
49
|
+
# Takes the metric size and turns it into a string.
|
50
|
+
# Example: "3.5 mm"
|
51
|
+
#
|
52
|
+
def metric_string
|
53
|
+
"#{@metric} mm"
|
54
|
+
end
|
55
|
+
|
56
|
+
# Sets @type to 'knitting' or 'crochet'.
|
57
|
+
#
|
58
|
+
def type
|
59
|
+
if hook || data[:crochet]
|
60
|
+
'crochet'
|
61
|
+
else
|
62
|
+
'knitting'
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def knitting?
|
67
|
+
type == 'knitting'
|
68
|
+
end
|
69
|
+
|
70
|
+
def crochet?
|
71
|
+
type == 'crochet'
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Ravelry
|
2
|
+
|
3
|
+
# Handles API request for the `Needles` endpoints. Always returns an array of {Ravelry::Needle} objects.
|
4
|
+
#
|
5
|
+
module Needles
|
6
|
+
extend self
|
7
|
+
|
8
|
+
# Get available sizes for each needle type. If you don't pass an argument, you'll get all knitting needle and crochet hook sizes.
|
9
|
+
#
|
10
|
+
# If you pass an argument (`'knitting'` or `'crochet'`), you will only get results that match that type.
|
11
|
+
#
|
12
|
+
# Arguments: needle type (string, optional)
|
13
|
+
#
|
14
|
+
def sizes(craft='')
|
15
|
+
result = Utils::Request.get("needles/sizes.json?craft=#{craft}", :needle_sizes)
|
16
|
+
result.map { |needle| Needle.new(needle) }
|
17
|
+
end
|
18
|
+
|
19
|
+
# Get needle types.
|
20
|
+
#
|
21
|
+
def types
|
22
|
+
result = Utils::Request.get("needles/types.json", :needle_types)
|
23
|
+
result.map { |needle| Needle.new(needle) }
|
24
|
+
end
|
25
|
+
|
26
|
+
# Get needle records for an individual user.
|
27
|
+
#
|
28
|
+
# Arguments: username (string, required)
|
29
|
+
#
|
30
|
+
def list(username)
|
31
|
+
result = Utils::Request.get("people/#{username}/needles/list.json", :needle_records)
|
32
|
+
result.map { |needle| Needle.new(needle) }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/ravelry/pattern.rb
CHANGED
@@ -2,7 +2,7 @@ module Ravelry
|
|
2
2
|
|
3
3
|
# `Ravelry::Pattern` corresponds to Pattern objects in Ravelry.
|
4
4
|
#
|
5
|
-
# This class requires your
|
5
|
+
# This class requires your configuration variables be set (see {file:README.md README}). API calls are authenticated using HTTP Basic Auth unless otherwise noted.
|
6
6
|
#
|
7
7
|
# If your `pattern.data` is missing one of the attributes below, that method will return `nil`.
|
8
8
|
#
|
@@ -64,7 +64,7 @@ module Ravelry
|
|
64
64
|
# To create all associated objects at once, call the following method after initialization:
|
65
65
|
#
|
66
66
|
# ```ruby
|
67
|
-
# pattern.
|
67
|
+
# pattern.build
|
68
68
|
# ```
|
69
69
|
#
|
70
70
|
# Note that this does not perform an API call: it creates the objects using the data returned from the initial `get` for your pattern object.
|
@@ -74,7 +74,7 @@ module Ravelry
|
|
74
74
|
# * `pattern.author` - a {Ravelry::Author} object
|
75
75
|
# * `pattern.categories` - an array of {Ravelry::Category} objects
|
76
76
|
# * `pattern.craft` - a {Ravelry::Craft} object
|
77
|
-
# * `pattern.needles` - an array of {Ravelry::
|
77
|
+
# * `pattern.needles` - an array of {Ravelry::Needle} objects
|
78
78
|
# * `pattern.packs` - array of {Ravelry::Pack} objects
|
79
79
|
# * `pattern.photos` - an array of {Ravelry::Photo} objects
|
80
80
|
# * `pattern.printings` - an array of {Raverly::Printing} objects
|
@@ -91,11 +91,11 @@ module Ravelry
|
|
91
91
|
attr_reader :author, :categories, :craft, :needles, :packs, :photos, :printings, :type, :yarns, :yarn_weights
|
92
92
|
|
93
93
|
# Handles GET API call and parses JSON response.
|
94
|
+
#
|
95
|
+
# Corresponds to Ravelry API endpoint `Patterns#show`
|
94
96
|
#
|
95
97
|
def get
|
96
|
-
|
97
|
-
result = JSON.parse(request.response_body, {symbolize_names: true})
|
98
|
-
@data = result[:pattern]
|
98
|
+
@data = Utils::Request.get("patterns/#{@id}.json", :pattern)
|
99
99
|
end
|
100
100
|
|
101
101
|
# Creates all objects associated with your pattern; returns nothing; sets `attr_readers`.
|
data/lib/ravelry/utils/build.rb
CHANGED
@@ -32,16 +32,16 @@ module Ravelry
|
|
32
32
|
@craft = Craft.new(data[:craft])
|
33
33
|
end
|
34
34
|
|
35
|
-
# Creates and returns an array of {Ravelry::
|
35
|
+
# Creates and returns an array of {Ravelry::Needle} objects.
|
36
36
|
#
|
37
37
|
# There is more than one API endpoint for Needles. This may not be the one you are looking for.
|
38
38
|
#
|
39
|
-
# See {Ravelry::
|
39
|
+
# See {Ravelry::Needle} for more information.
|
40
40
|
#
|
41
41
|
def self.needles(data)
|
42
42
|
@needles = []
|
43
43
|
data[:pattern_needle_sizes].each do |ndl|
|
44
|
-
@needles <<
|
44
|
+
@needles << Needle.new(ndl)
|
45
45
|
end
|
46
46
|
@needles
|
47
47
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Ravelry
|
2
|
+
module Utils
|
3
|
+
module Request
|
4
|
+
extend self
|
5
|
+
|
6
|
+
def get(url, key)
|
7
|
+
request = Typhoeus::Request.get("https://api.ravelry.com/#{url}", userpwd: "#{Ravelry.configuration.access_key}:#{Ravelry.configuration.personal_key}")
|
8
|
+
data = JSON.parse(request.response_body, {symbolize_names: true})
|
9
|
+
return data[key] if key
|
10
|
+
return data
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/ravelry/version.rb
CHANGED
@@ -1,20 +1,16 @@
|
|
1
1
|
require_relative '../spec_helper'
|
2
2
|
|
3
|
-
describe Ravelry::
|
3
|
+
describe Ravelry::Needle do
|
4
4
|
before do
|
5
|
-
@ndl = Ravelry::
|
5
|
+
@ndl = Ravelry::Needle.new(needle)
|
6
6
|
@data = needle
|
7
7
|
end
|
8
8
|
|
9
9
|
it 'creates an instance of Needle' do
|
10
|
-
expect(@ndl).to be_instance_of(Ravelry::
|
10
|
+
expect(@ndl).to be_instance_of(Ravelry::Needle)
|
11
11
|
end
|
12
12
|
|
13
13
|
context 'has and sets reader attributes for' do
|
14
|
-
it 'type' do
|
15
|
-
expect(@ndl.type).to eq('knitting')
|
16
|
-
end
|
17
|
-
|
18
14
|
it 'hook' do
|
19
15
|
expect(@ndl.hook).to eq(@data[:hook])
|
20
16
|
end
|
@@ -26,10 +22,6 @@ describe Ravelry::PatternNeedle do
|
|
26
22
|
it 'metric' do
|
27
23
|
expect(@ndl.metric).to eq(@data[:metric])
|
28
24
|
end
|
29
|
-
|
30
|
-
it 'knitting' do
|
31
|
-
expect(@ndl.knitting).to eq(@data[:name])
|
32
|
-
end
|
33
25
|
end
|
34
26
|
|
35
27
|
context 'class methods' do
|
@@ -37,7 +29,7 @@ describe Ravelry::PatternNeedle do
|
|
37
29
|
ndl = { :hook=>"E", :us_steel=>"00", :name=>"US 4 - 3.5 mm",
|
38
30
|
:crochet=>true, :metric=>3.5, :knitting=>false, :us=>"4 ",
|
39
31
|
:id=>4 }
|
40
|
-
needle = Ravelry::
|
32
|
+
needle = Ravelry::Needle.new(ndl)
|
41
33
|
expect(needle.type).to eq('crochet')
|
42
34
|
end
|
43
35
|
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
|
3
|
+
describe Ravelry::Needles do
|
4
|
+
context '#sizes' do
|
5
|
+
it 'should return an array of needles' do
|
6
|
+
result = Ravelry::Needles.sizes
|
7
|
+
expect(result.first).to be_instance_of(Ravelry::Needle)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
context '#types' do
|
12
|
+
it 'should return an array of needles' do
|
13
|
+
result = Ravelry::Needles.types
|
14
|
+
expect(result.first).to be_instance_of(Ravelry::Needle)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context '#list' do
|
19
|
+
it 'should return an array of needles' do
|
20
|
+
result = Ravelry::Needles.list("feministy")
|
21
|
+
expect(result.first).to be_instance_of(Ravelry::Needle)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ravelry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Liz Abinante
|
@@ -76,9 +76,10 @@ files:
|
|
76
76
|
- lib/ravelry/craft.rb
|
77
77
|
- lib/ravelry/data.rb
|
78
78
|
- lib/ravelry/misc.rb
|
79
|
+
- lib/ravelry/needle.rb
|
80
|
+
- lib/ravelry/needles.rb
|
79
81
|
- lib/ravelry/pack.rb
|
80
82
|
- lib/ravelry/pattern.rb
|
81
|
-
- lib/ravelry/pattern_needle.rb
|
82
83
|
- lib/ravelry/pattern_type.rb
|
83
84
|
- lib/ravelry/photo.rb
|
84
85
|
- lib/ravelry/printing.rb
|
@@ -86,6 +87,7 @@ files:
|
|
86
87
|
- lib/ravelry/user.rb
|
87
88
|
- lib/ravelry/user_site.rb
|
88
89
|
- lib/ravelry/utils/build.rb
|
90
|
+
- lib/ravelry/utils/request.rb
|
89
91
|
- lib/ravelry/utils/utilities.rb
|
90
92
|
- lib/ravelry/version.rb
|
91
93
|
- lib/ravelry/yarn.rb
|
@@ -101,8 +103,9 @@ files:
|
|
101
103
|
- spec/ravelry/craft_spec.rb
|
102
104
|
- spec/ravelry/data_spec.rb
|
103
105
|
- spec/ravelry/misc_spec.rb
|
106
|
+
- spec/ravelry/needle_spec.rb
|
107
|
+
- spec/ravelry/needles_spec.rb
|
104
108
|
- spec/ravelry/pack_spec.rb
|
105
|
-
- spec/ravelry/pattern_needle_spec.rb
|
106
109
|
- spec/ravelry/pattern_spec.rb
|
107
110
|
- spec/ravelry/pattern_type_spec.rb
|
108
111
|
- spec/ravelry/photo_spec.rb
|
@@ -133,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
133
136
|
version: '0'
|
134
137
|
requirements: []
|
135
138
|
rubyforge_project:
|
136
|
-
rubygems_version: 2.
|
139
|
+
rubygems_version: 2.2.2
|
137
140
|
signing_key:
|
138
141
|
specification_version: 4
|
139
142
|
summary: Ruby gem for accessing the Ravelry API.
|
@@ -148,8 +151,9 @@ test_files:
|
|
148
151
|
- spec/ravelry/craft_spec.rb
|
149
152
|
- spec/ravelry/data_spec.rb
|
150
153
|
- spec/ravelry/misc_spec.rb
|
154
|
+
- spec/ravelry/needle_spec.rb
|
155
|
+
- spec/ravelry/needles_spec.rb
|
151
156
|
- spec/ravelry/pack_spec.rb
|
152
|
-
- spec/ravelry/pattern_needle_spec.rb
|
153
157
|
- spec/ravelry/pattern_spec.rb
|
154
158
|
- spec/ravelry/pattern_type_spec.rb
|
155
159
|
- spec/ravelry/photo_spec.rb
|
@@ -160,3 +164,4 @@ test_files:
|
|
160
164
|
- spec/ravelry/yarn_weight_spec.rb
|
161
165
|
- spec/ravelry_spec.rb
|
162
166
|
- spec/spec_helper.rb
|
167
|
+
has_rdoc:
|
@@ -1,54 +0,0 @@
|
|
1
|
-
module Ravelry
|
2
|
-
|
3
|
-
# The information used to create `Ravelry::PatternNeedle` objects comes from {Ravelry::Pattern} objects.
|
4
|
-
#
|
5
|
-
# You should not create `PatternNeedle` objects manually; they are all created–and owned–by a {Ravelry::Pattern}.
|
6
|
-
#
|
7
|
-
# Note that there are other API endpoints for Needles; this might not be the one that you're looking for.
|
8
|
-
#
|
9
|
-
# See {Ravelry::Pattern} for more information about `Pattern` objects.
|
10
|
-
#
|
11
|
-
class PatternNeedle
|
12
|
-
|
13
|
-
attr_reader :type, :hook, :us, :metric, :knitting
|
14
|
-
|
15
|
-
def initialize(needle)
|
16
|
-
@needle = needle
|
17
|
-
# Crochet hook size.
|
18
|
-
#
|
19
|
-
@hook = needle[:hook]
|
20
|
-
# US size for knitting needles (Integer or Float).
|
21
|
-
#
|
22
|
-
@us = needle[:us]
|
23
|
-
# Metric size for knitting needles (Integer or Float).
|
24
|
-
#
|
25
|
-
@metric = needle[:metric]
|
26
|
-
# Combination of US and metric.
|
27
|
-
# Example: "US 4 - 3.5 mm"
|
28
|
-
#
|
29
|
-
@knitting = needle[:name]
|
30
|
-
end
|
31
|
-
|
32
|
-
# Sets @type to 'knitting' or 'crochet'.
|
33
|
-
#
|
34
|
-
def type
|
35
|
-
@type = 'knitting' if @needle[:knitting]
|
36
|
-
@type = 'crochet' if @needle[:crochet]
|
37
|
-
@type
|
38
|
-
end
|
39
|
-
|
40
|
-
# Takes the US size and turns it into a sentence.
|
41
|
-
# Example: "US 4"
|
42
|
-
#
|
43
|
-
def us_string
|
44
|
-
"US #{@us}".strip
|
45
|
-
end
|
46
|
-
|
47
|
-
# Takes the metric size and turns it into a sentence.
|
48
|
-
# Example: "3.5 mm"
|
49
|
-
#
|
50
|
-
def metric_string
|
51
|
-
"#{@metric} mm"
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|