Class: Ravelry::Needle

Inherits:
Object
  • Object
show all
Defined in:
lib/ravelry/needle.rb

Overview

The API endpoint for fetching ‘Needle` objects can be found in Needles.

A ‘Needle` object can be created by several different endpoints but is currently only implemented in Misc.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#commentObject (readonly)

Returns the value of attribute comment.



8
9
10
# File 'lib/ravelry/needle.rb', line 8

def comment
  @comment
end

#dataObject (readonly)

Returns the value of attribute data.



8
9
10
# File 'lib/ravelry/needle.rb', line 8

def data
  @data
end

#descriptionObject (readonly)

Returns the value of attribute description.



8
9
10
# File 'lib/ravelry/needle.rb', line 8

def description
  @description
end

#hookObject (readonly)

Returns the value of attribute hook.



8
9
10
# File 'lib/ravelry/needle.rb', line 8

def hook
  @hook
end

#idObject (readonly)

Returns the value of attribute id.



8
9
10
# File 'lib/ravelry/needle.rb', line 8

def id
  @id
end

#lengthObject (readonly)

Returns the value of attribute length.



8
9
10
# File 'lib/ravelry/needle.rb', line 8

def length
  @length
end

#metricObject (readonly)

Returns the value of attribute metric.



8
9
10
# File 'lib/ravelry/needle.rb', line 8

def metric
  @metric
end

#metric_nameObject (readonly)

Returns the value of attribute metric_name.



8
9
10
# File 'lib/ravelry/needle.rb', line 8

def metric_name
  @metric_name
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/ravelry/needle.rb', line 8

def name
  @name
end

#needle_size_idObject (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_typeObject (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_idObject (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_metricObject (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_nameObject (readonly)

Returns the value of attribute type_name.



8
9
10
# File 'lib/ravelry/needle.rb', line 8

def type_name
  @type_name
end

#usObject (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

Returns:

  • (Boolean)


70
71
72
# File 'lib/ravelry/needle.rb', line 70

def crochet?
  type == 'crochet'
end

#knitting?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/ravelry/needle.rb', line 66

def knitting?
  type == 'knitting'
end

#metric_stringObject

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

#typeObject

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_stringObject

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