lighterpack-parser 1.0.0 → 1.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 85fed15af6ad0ccfbba49c9960cf80e47fee71cbdce5166746e5788df489127d
4
- data.tar.gz: dbf4da779516e9ba651846a1457fcdfa52142313643235f5cbc7500778d9baec
3
+ metadata.gz: 7aad45ab474c77260d595b41456b949ab8d3ad658bd5a13d32cfd48728323def
4
+ data.tar.gz: '09ecbf0c0036256a9cf0cfd6657150775ba0b94b08144431e54a536465592695'
5
5
  SHA512:
6
- metadata.gz: 1e35ae9d5211815cef892b469d26e4e79163698465e2b213e8f394a0d2f9546ddc007e7a182684513aff24579281fe719581d3156c3fc6323134f48af2d6067f
7
- data.tar.gz: c90687504af99ace152a1bf2749362d70d004e37e3cd9baf50aee6adbe0fbce4869ba57ea7b6b7b74b617a6bac7ece5954dc4fe1c2e365377ffc110711efb8bb
6
+ metadata.gz: e632d196be2456197d2081a5de0ddc10b9bff3efbba3d34920a0795027cdc6b0e8a4869e7a827e4b41069a5d98c943a466266409af1c6916a65ded252ebd9fcb
7
+ data.tar.gz: 40633982fd1e80c6e34145b1c4d0dab8cfdfc83475d67f442404242a087db9ed6ebdb7346a87a54394d0f9f24af3c111f89171e9e589478eee2346011e1efa05
data/README.md CHANGED
@@ -2,41 +2,81 @@
2
2
 
3
3
  A Ruby gem for parsing Lighterpack lists from HTML or URLs.
4
4
 
5
+ Used by [Goulight](https://goulight.com). Source: [github.com/goulight/lighterpack-parser](https://github.com/goulight/lighterpack-parser).
6
+
5
7
  ## Installation
6
8
 
7
- This gem is used as a local dependency in the Packlista project. It's referenced in the backend `Gemfile`:
9
+ Add to your `Gemfile`:
8
10
 
9
11
  ```ruby
10
- gem 'lighterpack_parser', path: '../lighterpack-parser'
12
+ gem 'lighterpack-parser', '~> 1.0'
13
+ ```
14
+
15
+ Then:
16
+
17
+ ```bash
18
+ bundle install
19
+ ```
20
+
21
+ Or install directly:
22
+
23
+ ```bash
24
+ gem install lighterpack-parser
11
25
  ```
12
26
 
13
27
  ## Usage
14
28
 
29
+ `LighterpackParser::Parser#parse` (and `LighterpackParser.parse_url`) return a **`LighterpackParser::List`** object with readers `name`, `description`, and `categories`. Each category is a **`LighterpackParser::Category`**; each item is a **`LighterpackParser::Item`**.
30
+
31
+ Call **`#to_h`** on the list (or on categories/items) if you need nested hashes (for example JSON APIs).
32
+
15
33
  ### Parse from HTML string
16
34
 
17
35
  ```ruby
18
36
  require 'lighterpack_parser'
19
37
 
20
38
  html = File.read('path/to/lighterpack.html')
21
- result = LighterpackParser::Parser.new(html: html).parse
22
-
23
- # Result structure:
24
- # {
39
+ list = LighterpackParser::Parser.new(html: html).parse
40
+
41
+ list.name # => "List Name"
42
+ list.description # => "List description" or nil
43
+ list.categories.first.name # => "Category Name"
44
+
45
+ item = list.categories.first.items.first
46
+ item.name # => "Item Name"
47
+ item.description # => "Item description" or nil
48
+ item.weight # => 476.0 # grams per unit
49
+ item.total_weight # => 476.0 # weight * quantity (grams)
50
+ item.quantity # => 1
51
+ item.image_url # => "https://..." or nil
52
+ item.consumable # => false
53
+ item.total_consumable_weight # => nil (or total grams if consumable)
54
+ item.worn # => false
55
+ item.worn_quantity # => nil (or 1 if worn)
56
+ item.total_worn_weight # => nil (or grams worn, weight × 1)
57
+
58
+ # Hash shape (matches nested #to_h):
59
+ list.to_h
60
+ # => {
25
61
  # name: "List Name",
26
- # description: "List description (optional)",
62
+ # description: nil,
27
63
  # categories: [
28
64
  # {
29
65
  # name: "Category Name",
30
- # description: "Category description (optional)",
66
+ # description: nil,
31
67
  # items: [
32
68
  # {
33
69
  # name: "Item Name",
34
70
  # description: "Item description",
35
- # weight: 476.0, # in grams
71
+ # weight: 476.0,
72
+ # total_weight: 476.0,
36
73
  # quantity: 1,
37
74
  # image_url: "https://...",
38
75
  # consumable: false,
39
- # worn: false
76
+ # total_consumable_weight: nil,
77
+ # worn: false,
78
+ # worn_quantity: nil,
79
+ # total_worn_weight: nil
40
80
  # }
41
81
  # ]
42
82
  # }
@@ -49,11 +89,10 @@ result = LighterpackParser::Parser.new(html: html).parse
49
89
  ```ruby
50
90
  require 'lighterpack_parser'
51
91
 
52
- # Using the parser directly
53
- result = LighterpackParser::Parser.new(url: 'https://lighterpack.com/r/b6q1kr').parse
92
+ list = LighterpackParser::Parser.new(url: 'https://lighterpack.com/r/b6q1kr').parse
54
93
 
55
94
  # Or using the convenience method
56
- result = LighterpackParser.parse_url('https://lighterpack.com/r/b6q1kr')
95
+ list = LighterpackParser.parse_url('https://lighterpack.com/r/b6q1kr')
57
96
  ```
58
97
 
59
98
  ## Running Tests
@@ -66,7 +105,8 @@ rspec
66
105
 
67
106
  ## Test Fixtures
68
107
 
69
- Test fixtures are stored in `test/fixtures/` and contain HTML from example Lighterpack lists:
108
+ Test fixtures are stored in `spec/fixtures/` and contain HTML from example Lighterpack lists:
109
+
70
110
  - `b6q1kr.html` - Ultimate Hike 2025
71
111
  - `adbf7c.html` - Example list 2
72
112
  - `h23rxt.html` - Example list 3
@@ -74,7 +114,7 @@ Test fixtures are stored in `test/fixtures/` and contain HTML from example Light
74
114
  To update fixtures, download fresh HTML:
75
115
 
76
116
  ```bash
77
- curl -s "https://lighterpack.com/r/b6q1kr" > test/fixtures/b6q1kr.html
117
+ curl -s "https://lighterpack.com/r/b6q1kr" > spec/fixtures/b6q1kr.html
78
118
  ```
79
119
 
80
120
  ## Features
@@ -83,17 +123,18 @@ curl -s "https://lighterpack.com/r/b6q1kr" > test/fixtures/b6q1kr.html
83
123
  - Extracts categories with descriptions
84
124
  - Extracts items with:
85
125
  - Name and description
86
- - Weight (automatically converted to grams)
126
+ - Weight per unit and total weight (automatically converted to grams)
87
127
  - Quantity
88
128
  - Image URLs
89
- - Consumable flag
90
- - Worn flag
129
+ - Consumable flag and total consumable weight when applicable
130
+ - Worn flag, worn quantity, and total worn weight when applicable
91
131
  - Supports weight units: oz, lb, g, kg (all converted to grams)
92
132
  - Handles both HTML strings and URLs
93
133
 
94
134
  ## Weight Conversion
95
135
 
96
136
  The parser automatically converts all weights to grams:
137
+
97
138
  - `oz` → multiply by 28.3495
98
139
  - `lb` → multiply by 453.592
99
140
  - `g` → use as-is
@@ -69,24 +69,5 @@ module LighterpackParser
69
69
  total_worn_weight: total_worn_weight
70
70
  }
71
71
  end
72
- alias worn? worn
73
- alias consumable? consumable
74
-
75
- # Convert to hash
76
- #
77
- # @return [Hash] Hash representation of the item
78
- def to_h
79
- {
80
- name: name, description: description,
81
- weight: weight, total_weight: total_weight,
82
-
83
- quantity: quantity,
84
- image_url: image_url,
85
- consumable: consumable,
86
- total_consumable_weight: total_consumable_weight,
87
- worn: worn, worn_quantity: worn_quantity,
88
- total_worn_weight: total_worn_weight
89
- }
90
- end
91
72
  end
92
73
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LighterpackParser
4
- VERSION = '1.0.0'
4
+ VERSION = '1.0.2'
5
5
  end
@@ -10,9 +10,13 @@ Gem::Specification.new do |spec|
10
10
 
11
11
  spec.summary = 'Parser for Lighterpack lists'
12
12
  spec.description = 'Parse Lighterpack HTML to extract list data including categories, items, weights, and metadata'
13
- spec.homepage = 'https://github.com/alex-ross/lighterpack-parser'
13
+ spec.homepage = 'https://github.com/goulight/lighterpack-parser'
14
14
  spec.license = 'MIT'
15
15
 
16
+ spec.metadata = {
17
+ 'source_code_uri' => 'https://github.com/goulight/lighterpack-parser'
18
+ }
19
+
16
20
  spec.required_ruby_version = '>= 3.0'
17
21
 
18
22
  spec.files = Dir['lib/**/*', 'spec/**/*', '*.md', '*.gemspec']
data/spec/item_spec.rb ADDED
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'open3'
4
+ require 'rbconfig'
5
+ require 'spec_helper'
6
+
7
+ RSpec.describe LighterpackParser::Item do
8
+ subject(:item) do
9
+ described_class.new(
10
+ name: 'Trail runners',
11
+ description: 'Worn on approach',
12
+ weight: 320.5,
13
+ total_weight: 641.0,
14
+ quantity: 2,
15
+ image_url: 'https://example.com/item.png',
16
+ consumable: true,
17
+ total_consumable_weight: 641.0,
18
+ worn: true,
19
+ worn_quantity: 1,
20
+ total_worn_weight: 320.5
21
+ )
22
+ end
23
+
24
+ describe 'predicate helpers' do
25
+ it 'keeps the boolean reader methods available as predicates' do
26
+ expect(item.worn?).to be(true)
27
+ expect(item.consumable?).to be(true)
28
+ end
29
+ end
30
+
31
+ describe '#to_h' do
32
+ it 'returns the same public hash representation' do
33
+ expect(item.to_h).to eq(
34
+ name: 'Trail runners',
35
+ description: 'Worn on approach',
36
+ weight: 320.5,
37
+ total_weight: 641.0,
38
+ quantity: 2,
39
+ image_url: 'https://example.com/item.png',
40
+ consumable: true,
41
+ total_consumable_weight: 641.0,
42
+ worn: true,
43
+ worn_quantity: 1,
44
+ total_worn_weight: 320.5
45
+ )
46
+ end
47
+ end
48
+
49
+ describe 'loading the file' do
50
+ it 'does not emit method redefinition warnings' do
51
+ stdout, stderr, status = Open3.capture3(
52
+ RbConfig.ruby,
53
+ '-w',
54
+ '-I',
55
+ File.expand_path('../lib', __dir__),
56
+ '-e',
57
+ 'require "lighterpack_parser/item"'
58
+ )
59
+
60
+ aggregate_failures do
61
+ expect(status.success?).to be(true), stdout + stderr
62
+ expect(stderr).not_to include('method redefined')
63
+ expect(stderr).not_to include('previous definition of')
64
+ end
65
+ end
66
+ end
67
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lighterpack-parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Packlista Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-01-02 00:00:00.000000000 Z
11
+ date: 2026-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -75,12 +75,14 @@ files:
75
75
  - spec/fixtures/adbf7c.html
76
76
  - spec/fixtures/b6q1kr.html
77
77
  - spec/fixtures/h23rxt.html
78
+ - spec/item_spec.rb
78
79
  - spec/parser_spec.rb
79
80
  - spec/spec_helper.rb
80
- homepage: https://github.com/alex-ross/lighterpack-parser
81
+ homepage: https://github.com/goulight/lighterpack-parser
81
82
  licenses:
82
83
  - MIT
83
- metadata: {}
84
+ metadata:
85
+ source_code_uri: https://github.com/goulight/lighterpack-parser
84
86
  post_install_message:
85
87
  rdoc_options: []
86
88
  require_paths: