Class: Ravelry::Needle
- Inherits:
-
Object
- Object
- Ravelry::Needle
- Defined in:
- lib/ravelry/needle.rb
Overview
Instance Attribute Summary collapse
-
#comment ⇒ Object
readonly
Returns the value of attribute comment.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#hook ⇒ Object
readonly
Returns the value of attribute hook.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#length ⇒ Object
readonly
Returns the value of attribute length.
-
#metric ⇒ Object
readonly
Returns the value of attribute metric.
-
#metric_name ⇒ Object
readonly
Returns the value of attribute metric_name.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#needle_size_id ⇒ Object
readonly
Returns the value of attribute needle_size_id.
-
#needle_type ⇒ Object
readonly
Returns the value of attribute needle_type.
-
#needle_type_id ⇒ Object
readonly
Returns the value of attribute needle_type_id.
-
#pretty_metric ⇒ Object
readonly
Returns the value of attribute pretty_metric.
-
#type_name ⇒ Object
readonly
Returns the value of attribute type_name.
-
#us ⇒ Object
readonly
Returns the value of attribute us.
Instance Method Summary collapse
- #crochet? ⇒ Boolean
-
#initialize(data) ⇒ Needle
constructor
A new instance of Needle.
- #knitting? ⇒ Boolean
-
#metric_string ⇒ Object
Takes the metric size and turns it into a string.
-
#type ⇒ Object
Sets @type to ‘knitting’ or ‘crochet’.
-
#us_string ⇒ Object
Takes the US size and turns it into a string.
Constructor Details
#initialize(data) ⇒ Needle
Returns a new instance of Needle.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/ravelry/needle.rb', line 9 def initialize(data) @data = data @id = data[:id] # Crochet hook size. # Corresponding to this metric size, if one exists. # @hook = data[:hook] # US size number corresponding to this metric size, if one exists # @us = data[:us] # Combination of US and metric. # Example: "US 4 - 3.5 mm" # @name = data[:name] # Metric designation for hook size. # @metric = data[:metric] # Metric size for knitting needles (Integer or Float). # @metric_name = data[:metric_name] # Metric size for knitting needles (pretty format). # @pretty_metric = data[:pretty_metric] @description = data[:description] @length = data[:length] @needle_size_id = data[:needle_size_id] @type_name = data[:type_name] @needle_type = data[:needle_type] @needle_type_id = data[:needle_type_id] @comment = data[:comment] end |
Instance Attribute Details
#comment ⇒ Object (readonly)
Returns the value of attribute comment.
8 9 10 |
# File 'lib/ravelry/needle.rb', line 8 def comment @comment end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
8 9 10 |
# File 'lib/ravelry/needle.rb', line 8 def data @data end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
8 9 10 |
# File 'lib/ravelry/needle.rb', line 8 def description @description end |
#hook ⇒ Object (readonly)
Returns the value of attribute hook.
8 9 10 |
# File 'lib/ravelry/needle.rb', line 8 def hook @hook end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
8 9 10 |
# File 'lib/ravelry/needle.rb', line 8 def id @id end |
#length ⇒ Object (readonly)
Returns the value of attribute length.
8 9 10 |
# File 'lib/ravelry/needle.rb', line 8 def length @length end |
#metric ⇒ Object (readonly)
Returns the value of attribute metric.
8 9 10 |
# File 'lib/ravelry/needle.rb', line 8 def metric @metric end |
#metric_name ⇒ Object (readonly)
Returns the value of attribute metric_name.
8 9 10 |
# File 'lib/ravelry/needle.rb', line 8 def metric_name @metric_name end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/ravelry/needle.rb', line 8 def name @name end |
#needle_size_id ⇒ Object (readonly)
Returns the value of attribute needle_size_id.
8 9 10 |
# File 'lib/ravelry/needle.rb', line 8 def needle_size_id @needle_size_id end |
#needle_type ⇒ Object (readonly)
Returns the value of attribute needle_type.
8 9 10 |
# File 'lib/ravelry/needle.rb', line 8 def needle_type @needle_type end |
#needle_type_id ⇒ Object (readonly)
Returns the value of attribute needle_type_id.
8 9 10 |
# File 'lib/ravelry/needle.rb', line 8 def needle_type_id @needle_type_id end |
#pretty_metric ⇒ Object (readonly)
Returns the value of attribute pretty_metric.
8 9 10 |
# File 'lib/ravelry/needle.rb', line 8 def pretty_metric @pretty_metric end |
#type_name ⇒ Object (readonly)
Returns the value of attribute type_name.
8 9 10 |
# File 'lib/ravelry/needle.rb', line 8 def type_name @type_name end |
#us ⇒ Object (readonly)
Returns the value of attribute us.
8 9 10 |
# File 'lib/ravelry/needle.rb', line 8 def us @us end |
Instance Method Details
#crochet? ⇒ Boolean
70 71 72 |
# File 'lib/ravelry/needle.rb', line 70 def crochet? type == 'crochet' end |
#knitting? ⇒ Boolean
66 67 68 |
# File 'lib/ravelry/needle.rb', line 66 def knitting? type == 'knitting' end |
#metric_string ⇒ Object
Takes the metric size and turns it into a string. Example: “3.5 mm”
52 53 54 |
# File 'lib/ravelry/needle.rb', line 52 def metric_string "#{@metric} mm" end |
#type ⇒ Object
Sets @type to ‘knitting’ or ‘crochet’.
58 59 60 61 62 63 64 |
# File 'lib/ravelry/needle.rb', line 58 def type if hook || data[:crochet] 'crochet' else 'knitting' end end |
#us_string ⇒ Object
Takes the US size and turns it into a string. Example: “US 4”
45 46 47 |
# File 'lib/ravelry/needle.rb', line 45 def us_string "US #{@us}".strip end |