fiber_pattern 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1385f6b59804f75b05ecea1e994ef99dbdf9466f5d19c464d7761c2b7ca7080a
4
+ data.tar.gz: f8487b4aac630f1cabf7c05c0b957e05178959590a2001f7c4a546adcf81dcde
5
+ SHA512:
6
+ metadata.gz: 3707e9546ce3fe0b29aba10ef1b90b13e40a7ee53ac2585aef670942b6e32d0f76bab53886178f2d59ed9add2af2777695e1a641926f8ce38181cbf6b0d667f2
7
+ data.tar.gz: 952066f10ac1083b16724a73db119e647b768dca933a9851d5c54bae6dad7f1c5fe1988b22ad6f858e5470f075fbd9ce08d04bcc4762551c6cdd4778d00ad321
data/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2026-03-14
4
+
5
+ - Adding offset repeat behavior
6
+ - Adding stitch repeat behavior
7
+ - Adding initial pattern cast-on math with `Sizing` module
8
+ - Initial release
@@ -0,0 +1,10 @@
1
+ # Code of Conduct
2
+
3
+ "fiber_pattern" follows [The Ruby Community Conduct Guideline](https://www.ruby-lang.org/en/conduct) in all "collaborative space", which is defined as community communications channels (such as mailing lists, submitted patches, commit comments, etc.):
4
+
5
+ * Participants will be tolerant of opposing views.
6
+ * Participants must ensure that their language and actions are free of personal attacks and disparaging personal remarks.
7
+ * When interpreting the words and actions of others, participants should always assume good intentions.
8
+ * Behaviour which can be reasonably considered harassment will not be tolerated.
9
+
10
+ If you have any concerns about behaviour within this project, please contact us at ["TODO: Write your email address"](mailto:"TODO: Write your email address").
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Meagan Waller
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,178 @@
1
+ # fiber_pattern
2
+
3
+ Tools for **pattern sizing, stitch repeats, and gauge-based calculations** for knitting and crochet.
4
+
5
+ `fiber_pattern` builds on the primitives provided by:
6
+
7
+ * [**fiber_units**](https://github.com/meaganewaller/fiber_units) — typed units for stitches, rows, and measurements
8
+ * [**fiber_gauge**](https://github.com/meaganewaller/fiber_gauge) — gauge swatch math
9
+
10
+ Together they enable **reliable pattern sizing and repeat calculations**.
11
+
12
+ ---
13
+
14
+ # Installation
15
+
16
+ Add this line to your application's Gemfile:
17
+
18
+ ```ruby
19
+ gem "fiber_pattern"
20
+ ```
21
+
22
+ Then run:
23
+
24
+ ```
25
+ bundle install
26
+ ```
27
+
28
+ Or install directly:
29
+
30
+ ```
31
+ gem install fiber_pattern
32
+ ```
33
+
34
+ # Dependencies
35
+
36
+ `fiber_pattern` is designed to work with:
37
+
38
+ ```
39
+ fiber_units
40
+ fiber_gauge
41
+ ```
42
+
43
+ These libraries provide the domain primitives used throughout the API.
44
+
45
+ # Basic Usage
46
+
47
+ Patterns often require calculating stitch counts from gauge and measurements.
48
+
49
+ Example gauge:
50
+
51
+ ```
52
+ 18 stitches over 4 inches
53
+ 24 rows over 4 inches
54
+ ```
55
+
56
+ Create a gauge object:
57
+
58
+ ```ruby
59
+ gauge = FiberGauge::Gauge.new(
60
+ stitches: 18.stitches,
61
+ rows: 24.rows,
62
+ width: 4.inches
63
+ )
64
+ ```
65
+
66
+ # Calculate Cast-On Stitches
67
+
68
+ You can determine how many stitches are needed for a target width.
69
+
70
+ ```ruby
71
+ sizing = FiberPattern::Sizing.new(gauge: gauge)
72
+
73
+ sizing.cast_on_for(20.inches)
74
+ # => 90 stitches
75
+ ```
76
+
77
+ Because:
78
+
79
+ ```
80
+ 18 stitches / 4 inches = 4.5 stitches per inch
81
+ 20 inches × 4.5 = 90 stitches
82
+ ```
83
+
84
+ # Pattern Stitch Repeats
85
+
86
+ Many patterns require stitch counts to be a **multiple of a repeat**.
87
+
88
+ Example: *multiple of 8 stitches*
89
+
90
+ ```ruby
91
+ sizing = FiberPattern::Sizing.new(
92
+ gauge: gauge,
93
+ stitch_repeat: 8.stitches
94
+ )
95
+
96
+ sizing.cast_on_for(38.inches)
97
+ # => 176 stitches
98
+ ```
99
+
100
+ Calculation:
101
+
102
+ ```
103
+ 38 inches × 4.5 spi = 171 stitches
104
+ rounded to nearest multiple of 8 → 176
105
+ ```
106
+
107
+ # Repeats With Offsets
108
+
109
+ Some stitch patterns require **multiples plus an offset**.
110
+
111
+ Example:
112
+
113
+ ```
114
+ multiple of 8 + 2
115
+ ```
116
+
117
+ ```ruby
118
+ sizing = FiberPattern::Sizing.new(
119
+ gauge: gauge,
120
+ stitch_repeat: 8.stitches,
121
+ repeat_offset: 2.stitches
122
+ )
123
+
124
+ sizing.cast_on_for(38.inches)
125
+ # => 178 stitches
126
+ ```
127
+
128
+ Calculation:
129
+
130
+ ```
131
+ 171 stitches
132
+ → adjusted to (multiple of 8 + 2)
133
+ → 178 stitches
134
+ ```
135
+
136
+ # Example: Sweater Sizing
137
+
138
+ ```ruby
139
+ gauge = FiberGauge::Gauge.new(
140
+ stitches: 20.stitches,
141
+ rows: 28.rows,
142
+ width: 4.inches
143
+ )
144
+
145
+ sizing = FiberPattern::Sizing.new(
146
+ gauge: gauge,
147
+ stitch_repeat: 8.stitches
148
+ )
149
+
150
+ chest = 40.inches
151
+
152
+ cast_on = sizing.cast_on_for(chest)
153
+ # => 200 stitches
154
+ ```
155
+
156
+ # Design Goals
157
+
158
+ `fiber_pattern` is designed to:
159
+
160
+ * make **pattern math predictable**
161
+ * integrate with **typed fiber measurement units**
162
+ * support **repeat-based stitch patterns**
163
+ * stay **small and composable**
164
+
165
+ It forms part of a broader fiber tooling ecosystem:
166
+
167
+ - [fiber_units](https://github.com/meaganewaller/fiber_units)
168
+ - [yarn_skein](https://github.com/meaganewaller/yarn_skein)
169
+ - [fiber_gauge](https://github.com/meaganewaller/fiber_gauge)
170
+ - [fiber_pattern](https://github.com/meaganewaller/fiber_pattern)
171
+
172
+ # Contributing
173
+
174
+ Bug reports and pull requests are welcome.
175
+
176
+ # License
177
+
178
+ MIT License
data/Rakefile ADDED
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+ require "yard"
6
+ require "yard/rake/yardoc_task"
7
+ require "standard/rake"
8
+
9
+ # YARD Documentation tasks
10
+ begin
11
+ namespace :doc do
12
+ desc "Generate YARD documentation"
13
+ YARD::Rake::YardocTask.new(:generate) do |t|
14
+ t.files = ["lib/**/*.rb", "-", "README.md"]
15
+ t.options = [
16
+ "--output-dir", "doc/yard",
17
+ "--markup", "markdown",
18
+ "--title", "YarnSkein - Yarn metadata and skein calculations",
19
+ "--readme", "README.md"
20
+ ]
21
+ end
22
+
23
+ desc "Regenerate documentation with cache reset"
24
+ task regenerate: ["doc:clean", "doc:generate"]
25
+
26
+ desc "Clean generated documentation"
27
+ task :clean do
28
+ rm_rf "doc/yard"
29
+ rm_rf ".yardoc"
30
+ end
31
+
32
+ desc "Start YARD server for local documentation viewing"
33
+ task :serve do
34
+ sh "bundle exec yard server --reload --port 8808"
35
+ end
36
+
37
+ desc "Validate YARD documentation coverage"
38
+ task :coverage do
39
+ sh "bundle exec yard stats --list-undoc"
40
+ end
41
+
42
+ desc "Generate complete documentation with coverage report"
43
+ task complete: [:generate, :coverage]
44
+ end
45
+
46
+ # Add shorthand aliases
47
+ task yard: "doc:generate"
48
+ task yard_server: "doc:serve"
49
+ task yard_clean: "doc:clean"
50
+ rescue LoadError
51
+ # YARD is only available in development/test environments
52
+ # Silence this warning in production where it's not needed
53
+ end
54
+
55
+ task :default do
56
+ Rake::Task["standard"].invoke
57
+ Rake::Task["spec"].invoke
58
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FiberPattern
4
+ # Calculates pattern sizing values from a provided gauge object.
5
+ class Sizing
6
+ # @return [Object] gauge object that responds to `required_stitches`
7
+ attr_reader :gauge
8
+
9
+ # @return [Object, nil] optional stitch repeat to round stitch counts to
10
+ attr_reader :stitch_repeat
11
+
12
+ # @return [Object] optional offset to apply when rounding to stitch repeat
13
+ attr_reader :repeat_offset
14
+
15
+ # @param gauge [Object] gauge object used to derive stitch counts
16
+ # @param stitch_repeat [Object, nil] optional stitch repeat to round stitch counts to
17
+ # @param repeat_offset [Object] optional offset to apply when rounding to stitch repeat
18
+ def initialize(gauge:, stitch_repeat: nil, repeat_offset: 0.stitches)
19
+ @gauge = gauge
20
+ @stitch_repeat = stitch_repeat
21
+ @repeat_offset = repeat_offset
22
+ end
23
+
24
+ # Computes the cast-on stitch count needed for a target width.
25
+ #
26
+ # @param width [Object] desired finished width in units accepted by the gauge
27
+ # @return [Integer] number of stitches required to reach the requested width
28
+ def cast_on_for(width)
29
+ stitches = gauge.required_stitches(width)
30
+
31
+ return stitches unless stitch_repeat
32
+
33
+ adjust_to_repeat(stitches)
34
+ end
35
+
36
+ private
37
+
38
+ # Adjusts a stitch count up to the nearest multiple of the stitch repeat.
39
+ # @param stitches [Object] stitch count to adjust
40
+ # @return [Integer] stitch count rounded up to the nearest multiple of the stitch repeat
41
+ def adjust_to_repeat(stitches)
42
+ repeat = stitch_repeat.value
43
+ offset = @repeat_offset.value
44
+
45
+ adjusted =
46
+ ((stitches.value - offset).to_f / repeat).ceil * repeat + offset
47
+
48
+ adjusted.stitches
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FiberPattern
4
+ # Current gem version.
5
+ VERSION = "0.1.0"
6
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "fiber_units"
4
+ require "fiber_gauge"
5
+ require_relative "fiber_pattern/version"
6
+ require_relative "fiber_pattern/sizing"
7
+
8
+ # Utilities for generating fiber pattern measurements from gauge data.
9
+ module FiberPattern
10
+ # Base error type for gem-specific failures.
11
+ class Error < StandardError; end
12
+ end
data/mise.toml ADDED
@@ -0,0 +1,2 @@
1
+ [tools]
2
+ ruby = "latest"
@@ -0,0 +1,4 @@
1
+ module FiberPattern
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fiber_pattern
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Meagan Waller
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: fiber_units
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: 0.3.1
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: 0.3.1
26
+ - !ruby/object:Gem::Dependency
27
+ name: fiber_gauge
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ description: A Ruby gem for calculating pattern sizes and stitch counts for knitting
41
+ and crochet projects.
42
+ email:
43
+ - meagan@meaganwaller.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - CHANGELOG.md
49
+ - CODE_OF_CONDUCT.md
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - lib/fiber_pattern.rb
54
+ - lib/fiber_pattern/sizing.rb
55
+ - lib/fiber_pattern/version.rb
56
+ - mise.toml
57
+ - sig/fiber_pattern.rbs
58
+ homepage: https://github.com/meaganewaller/fiber_pattern
59
+ licenses:
60
+ - MIT
61
+ metadata:
62
+ homepage_uri: https://github.com/meaganewaller/fiber_pattern
63
+ source_code_uri: https://github.com/meaganewaller/fiber_pattern
64
+ changelog_uri: https://github.com/meaganewaller/fiber_pattern/blob/main/CHANGELOG.md
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 3.2.0
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubygems_version: 4.0.3
80
+ specification_version: 4
81
+ summary: Pattern sizing and stitch math for knitting and crochet.
82
+ test_files: []