fiber_pattern 0.4.0 → 0.5.0
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/lib/fiber_pattern/sizing.rb +8 -2
- data/lib/fiber_pattern/stitch_pattern.rb +139 -0
- data/lib/fiber_pattern/version.rb +1 -1
- data/lib/fiber_pattern.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 86098b154ca5d374ea82112b74c4bcfde885d6da22aa071c4c0f8b87fc2c89bd
|
|
4
|
+
data.tar.gz: 6744cff995e936ff00774ffa69e1829c1992cfe5901d491ba233fcd5e734d5fe
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c9daa9034c4a2a6b5d46c3e09a999a78c11245424163ac792194d8e9d575c95f7146d4e447de386c642ea51cc17b9a8b7477533a04ba7080fc0c09b4b5df3c49
|
|
7
|
+
data.tar.gz: a7595ab55c4c0fa5861a39af96d373958cc6f39359f1bb2feddfa3b94187e4de7cf81c403cb3b17ac92c0fcdf395a04526507c22a25c91d04c832b182f828c3d
|
data/lib/fiber_pattern/sizing.rb
CHANGED
|
@@ -9,11 +9,16 @@ module FiberPattern
|
|
|
9
9
|
# @return [FiberPattern::Repeat, nil] optional stitch repeat to round stitch counts to
|
|
10
10
|
attr_reader :repeat
|
|
11
11
|
|
|
12
|
+
# @return [FiberPattern::StitchPattern, nil] optional stitch pattern for width adjustment
|
|
13
|
+
attr_reader :stitch_pattern
|
|
14
|
+
|
|
12
15
|
# @param gauge [Object] gauge object used to derive stitch counts
|
|
13
16
|
# @param repeat [FiberPattern::Repeat, nil] optional stitch repeat to round stitch counts to
|
|
14
|
-
|
|
17
|
+
# @param stitch_pattern [FiberPattern::StitchPattern, nil] optional stitch pattern for width adjustment
|
|
18
|
+
def initialize(gauge:, repeat: nil, stitch_pattern: nil)
|
|
15
19
|
@gauge = gauge
|
|
16
20
|
@repeat = repeat
|
|
21
|
+
@stitch_pattern = stitch_pattern
|
|
17
22
|
end
|
|
18
23
|
|
|
19
24
|
# Calculates the number of stitches required to reach a given width, based on the provided gauge.
|
|
@@ -21,7 +26,8 @@ module FiberPattern
|
|
|
21
26
|
# @param width [Object] desired finished width in units accepted by the gauge
|
|
22
27
|
# @return [Integer] number of stitches required to reach the requested width
|
|
23
28
|
def cast_on_for(width)
|
|
24
|
-
|
|
29
|
+
adjusted_width = stitch_pattern ? stitch_pattern.adjust_width(width) : width
|
|
30
|
+
stitches = gauge.required_stitches(adjusted_width)
|
|
25
31
|
|
|
26
32
|
return stitches unless repeat
|
|
27
33
|
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module FiberPattern
|
|
4
|
+
# Models how a stitch pattern affects fabric dimensions and yarn consumption
|
|
5
|
+
# relative to stockinette. Cables compress width and consume more yarn;
|
|
6
|
+
# lace opens up fabric and uses less yarn per area.
|
|
7
|
+
class StitchPattern
|
|
8
|
+
# @return [String] human-readable name of the stitch pattern
|
|
9
|
+
attr_reader :name
|
|
10
|
+
|
|
11
|
+
# @return [FiberPattern::Repeat, nil] optional stitch repeat for this pattern
|
|
12
|
+
attr_reader :repeat
|
|
13
|
+
|
|
14
|
+
# @return [Float] multiplier vs stockinette for fabric width (< 1 = pulls in)
|
|
15
|
+
attr_reader :width_factor
|
|
16
|
+
|
|
17
|
+
# @return [Float] multiplier vs stockinette for yarn consumption (> 1 = uses more)
|
|
18
|
+
attr_reader :yarn_factor
|
|
19
|
+
|
|
20
|
+
# @param name [String] human-readable name of the stitch pattern
|
|
21
|
+
# @param repeat [FiberPattern::Repeat, nil] optional stitch repeat
|
|
22
|
+
# @param width_factor [Float] width multiplier vs stockinette (default: 1.0)
|
|
23
|
+
# @param yarn_factor [Float] yarn consumption multiplier vs stockinette (default: 1.0)
|
|
24
|
+
def initialize(name:, repeat: nil, width_factor: 1.0, yarn_factor: 1.0)
|
|
25
|
+
@name = name.freeze
|
|
26
|
+
@repeat = repeat
|
|
27
|
+
@width_factor = width_factor.to_f
|
|
28
|
+
@yarn_factor = yarn_factor.to_f
|
|
29
|
+
validate!
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Returns the stockinette-equivalent width needed to achieve the desired
|
|
33
|
+
# finished width in this stitch pattern.
|
|
34
|
+
#
|
|
35
|
+
# @param width [FiberUnits::Length] desired finished width
|
|
36
|
+
# @return [FiberUnits::Length] stockinette-equivalent width to knit
|
|
37
|
+
def adjust_width(width)
|
|
38
|
+
(width.value / width_factor).round(2).public_send(width.unit)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Adjusts a base yardage estimate to account for this pattern's yarn consumption.
|
|
42
|
+
#
|
|
43
|
+
# @param yardage [FiberUnits::Length] base yardage assuming stockinette
|
|
44
|
+
# @return [FiberUnits::Length] adjusted yardage for this stitch pattern
|
|
45
|
+
def adjust_yardage(yardage)
|
|
46
|
+
(yardage.value * yarn_factor).round(2).public_send(yardage.unit)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Preset definitions for common stitch patterns.
|
|
50
|
+
|
|
51
|
+
def self.stockinette
|
|
52
|
+
new(name: "Stockinette", width_factor: 1.0, yarn_factor: 1.0)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def self.garter
|
|
56
|
+
new(name: "Garter", width_factor: 1.0, yarn_factor: 1.05)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def self.rib_1x1
|
|
60
|
+
new(
|
|
61
|
+
name: "1x1 Rib",
|
|
62
|
+
repeat: Repeat.new(multiple: 2.stitches),
|
|
63
|
+
width_factor: 0.90,
|
|
64
|
+
yarn_factor: 1.10
|
|
65
|
+
)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def self.rib_2x2
|
|
69
|
+
new(
|
|
70
|
+
name: "2x2 Rib",
|
|
71
|
+
repeat: Repeat.new(multiple: 4.stitches),
|
|
72
|
+
width_factor: 0.85,
|
|
73
|
+
yarn_factor: 1.12
|
|
74
|
+
)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def self.seed
|
|
78
|
+
new(
|
|
79
|
+
name: "Seed Stitch",
|
|
80
|
+
repeat: Repeat.new(multiple: 2.stitches),
|
|
81
|
+
width_factor: 0.95,
|
|
82
|
+
yarn_factor: 1.05
|
|
83
|
+
)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# Crochet preset definitions.
|
|
87
|
+
|
|
88
|
+
def self.single_crochet
|
|
89
|
+
new(name: "Single Crochet", width_factor: 1.0, yarn_factor: 1.0)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def self.half_double_crochet
|
|
93
|
+
new(name: "Half Double Crochet", width_factor: 1.05, yarn_factor: 1.15)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def self.double_crochet
|
|
97
|
+
new(name: "Double Crochet", width_factor: 1.10, yarn_factor: 1.25)
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def self.treble_crochet
|
|
101
|
+
new(name: "Treble Crochet", width_factor: 1.15, yarn_factor: 1.35)
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def self.moss_stitch
|
|
105
|
+
new(
|
|
106
|
+
name: "Moss Stitch",
|
|
107
|
+
repeat: Repeat.new(multiple: 2.stitches),
|
|
108
|
+
width_factor: 1.05,
|
|
109
|
+
yarn_factor: 1.10
|
|
110
|
+
)
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def self.shell_stitch
|
|
114
|
+
new(
|
|
115
|
+
name: "Shell Stitch",
|
|
116
|
+
repeat: Repeat.new(multiple: 6.stitches, offset: 1.stitches),
|
|
117
|
+
width_factor: 1.15,
|
|
118
|
+
yarn_factor: 1.30
|
|
119
|
+
)
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def self.v_stitch
|
|
123
|
+
new(
|
|
124
|
+
name: "V-Stitch",
|
|
125
|
+
repeat: Repeat.new(multiple: 2.stitches),
|
|
126
|
+
width_factor: 1.10,
|
|
127
|
+
yarn_factor: 0.90
|
|
128
|
+
)
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
private
|
|
132
|
+
|
|
133
|
+
def validate!
|
|
134
|
+
raise ArgumentError, "name must be a non-empty string" if name.nil? || name.empty?
|
|
135
|
+
raise ArgumentError, "width_factor must be positive" unless width_factor.positive?
|
|
136
|
+
raise ArgumentError, "yarn_factor must be positive" unless yarn_factor.positive?
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
end
|
data/lib/fiber_pattern.rb
CHANGED
|
@@ -5,6 +5,7 @@ require "fiber_gauge"
|
|
|
5
5
|
require_relative "fiber_pattern/version"
|
|
6
6
|
require_relative "fiber_pattern/sizing"
|
|
7
7
|
require_relative "fiber_pattern/repeat"
|
|
8
|
+
require_relative "fiber_pattern/stitch_pattern"
|
|
8
9
|
require_relative "fiber_pattern/scaling"
|
|
9
10
|
require_relative "fiber_pattern/shaping"
|
|
10
11
|
require_relative "fiber_pattern/grade_rules"
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: fiber_pattern
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Meagan Waller
|
|
@@ -86,6 +86,7 @@ files:
|
|
|
86
86
|
- lib/fiber_pattern/shaping.rb
|
|
87
87
|
- lib/fiber_pattern/size_chart.rb
|
|
88
88
|
- lib/fiber_pattern/sizing.rb
|
|
89
|
+
- lib/fiber_pattern/stitch_pattern.rb
|
|
89
90
|
- lib/fiber_pattern/version.rb
|
|
90
91
|
- sig/fiber_pattern.rbs
|
|
91
92
|
homepage: https://github.com/meaganewaller/craftos/tree/main/gems/fiber_pattern
|