nrb-beerxml 0.0.3 → 0.0.4
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/README.md +46 -6
- data/lib/nrb/beerxml.rb +24 -0
- data/lib/{beerxml → nrb/beerxml}/builder.rb +0 -1
- data/lib/nrb/beerxml/equipment.rb +36 -0
- data/lib/nrb/beerxml/fermentable.rb +31 -0
- data/lib/nrb/beerxml/hop.rb +36 -0
- data/lib/{beerxml → nrb/beerxml}/inflector.rb +0 -0
- data/lib/nrb/beerxml/mash.rb +33 -0
- data/lib/nrb/beerxml/mash_step.rb +24 -0
- data/lib/nrb/beerxml/misc.rb +22 -0
- data/lib/{beerxml → nrb/beerxml}/parser.rb +0 -0
- data/lib/nrb/beerxml/recipe.rb +107 -0
- data/lib/nrb/beerxml/record.rb +47 -0
- data/lib/{beerxml → nrb/beerxml}/record_set.rb +0 -0
- data/lib/nrb/beerxml/record_validators.rb +6 -0
- data/lib/{beerxml → nrb/beerxml}/record_validators/boolean_validator.rb +0 -0
- data/lib/{beerxml → nrb/beerxml}/record_validators/percentage_validator.rb +0 -0
- data/lib/nrb/beerxml/style.rb +47 -0
- data/lib/nrb/beerxml/version.rb +4 -0
- data/lib/nrb/beerxml/water.rb +24 -0
- data/lib/nrb/beerxml/yeast.rb +36 -0
- data/spec/cases/beerxml/record_validators/boolean_validator_spec.rb +1 -1
- data/spec/cases/beerxml/record_validators/percentage_validator_spec.rb +1 -1
- data/spec/cases/beerxml/version_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- metadata +22 -22
- data/lib/beerxml.rb +0 -24
- data/lib/beerxml/equipment.rb +0 -38
- data/lib/beerxml/fermentable.rb +0 -33
- data/lib/beerxml/hop.rb +0 -38
- data/lib/beerxml/mash.rb +0 -35
- data/lib/beerxml/mash_step.rb +0 -26
- data/lib/beerxml/misc.rb +0 -24
- data/lib/beerxml/recipe.rb +0 -109
- data/lib/beerxml/record.rb +0 -49
- data/lib/beerxml/record_validators.rb +0 -8
- data/lib/beerxml/style.rb +0 -49
- data/lib/beerxml/version.rb +0 -6
- data/lib/beerxml/water.rb +0 -26
- data/lib/beerxml/yeast.rb +0 -38
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03033c9e27c70f80d8743be2e283b166fb64e7a4
|
4
|
+
data.tar.gz: 1449230fbd782ba350b23b2e8dda9a36dabaec9a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2ab79db6af27da53a608e8d35923cd51930eff78e51dbd21de6294025e10794e28c58695342220d0b649c6f6514626879610d7c59d52319abd3f66a654a6d8e
|
7
|
+
data.tar.gz: f81eae1407baafc9fbabec27561439076e57b6fd07e2ff1bbdf8351654bdef50c0a5ee9dae2f9ba34f8c307100279747db26b98f81ce22ed0a9375959dcd370a
|
data/README.md
CHANGED
@@ -1,10 +1,9 @@
|
|
1
|
-
# NRB::Beerxml
|
1
|
+
# NRB::Beerxml – A [BeerXML](http://www.beerxml.com/) parser
|
2
2
|
|
3
3
|
[](https://codeclimate.com/github/NewRepublicBrewing/beerxml)
|
4
4
|
|
5
|
-
A BeerXML parser
|
6
5
|
|
7
|
-
##
|
6
|
+
## Install
|
8
7
|
|
9
8
|
Add this line to your application's Gemfile:
|
10
9
|
|
@@ -20,14 +19,55 @@ Or install it yourself as:
|
|
20
19
|
|
21
20
|
% gem install nrb-beerxml
|
22
21
|
|
23
|
-
##
|
22
|
+
## Parse
|
24
23
|
|
24
|
+
Parse a BeerXML file
|
25
25
|
|
26
|
+
```ruby
|
27
|
+
require `nrb/beerxml`
|
28
|
+
parser = NRB::BeerXML::Parser.new
|
29
|
+
parser.parse file_path
|
30
|
+
=> #<NRB::BeerXML::Equipment:0x007fbe501e4298 @name="Brew Pot", ...>
|
31
|
+
```
|
32
|
+
|
33
|
+
`parse` can handle a `String` pathname or an `IO` containing the BeerXML.
|
34
|
+
|
35
|
+
### Builder
|
36
|
+
|
37
|
+
The parser uses a builder class to construct `NRB::BeerXML::Record` objects. If you would rather get back some other class of object (for example a `ActiveRecord` model) just give it your own builder class at initialization.
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
parser = NRB::BeerXML::Parser.new buider: MyBuilder
|
41
|
+
```
|
42
|
+
|
43
|
+
Your builder should implement a `build(type)` method which returns a new object of the requested type. `type` will be an underscored string.
|
44
|
+
|
45
|
+
### Reader
|
46
|
+
|
47
|
+
NRB::BeerXML uses Nokogiri by default. If you want to use another reader, simply pass the class name to the Parser's initializer.
|
26
48
|
|
27
|
-
|
49
|
+
```ruby
|
50
|
+
parser = NRB::BeerXML::Parser.new reader: SomeXMLReader
|
51
|
+
```
|
52
|
+
|
53
|
+
The reader should implement a `parse(stream)` method which returns a document. The document object should implement `#children`, `#name`, `#root`, `#text` & `#text?`
|
28
54
|
|
29
|
-
|
55
|
+
## Bonus
|
56
|
+
|
57
|
+
If `BeerXML` is not in your namespace before `require 'nrb/beerxml'` you can leave off the `NRB` prefix when referencing classes.
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
defined?(BeerXML) || BeerXML = NRB::BeerXML
|
61
|
+
```
|
62
|
+
|
63
|
+
## Contribute
|
64
|
+
|
65
|
+
1. [Fork me](https://github.com/NewRepublicBrewing/nrb-beerxml/fork)
|
30
66
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
31
67
|
3. Commit your changes (`git commit -am 'Add some beers'`)
|
32
68
|
4. Push to the branch (`git push origin my-new-beer`)
|
33
69
|
5. Create a Pull Request
|
70
|
+
|
71
|
+
## Contributors
|
72
|
+
|
73
|
+
@brundage at the [New Republic Brewing Company](https://github.com/NewRepublicBrewing)
|
data/lib/nrb/beerxml.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
module NRB
|
2
|
+
module BeerXML
|
3
|
+
|
4
|
+
autoload :Builder, 'nrb/beerxml/builder'
|
5
|
+
autoload :Equipment, 'nrb/beerxml/equipment'
|
6
|
+
autoload :Fermentable, 'nrb/beerxml/fermentable'
|
7
|
+
autoload :Hop, 'nrb/beerxml/hop'
|
8
|
+
autoload :Inflector, 'nrb/beerxml/inflector'
|
9
|
+
autoload :Mash, 'nrb/beerxml/mash'
|
10
|
+
autoload :MashStep, 'nrb/beerxml/mash_step'
|
11
|
+
autoload :Misc, 'nrb/beerxml/misc'
|
12
|
+
autoload :Parser, 'nrb/beerxml/parser'
|
13
|
+
autoload :Recipe, 'nrb/beerxml/recipe'
|
14
|
+
autoload :Record, 'nrb/beerxml/record'
|
15
|
+
autoload :RecordSet, 'nrb/beerxml/record_set'
|
16
|
+
autoload :RecordValidators, 'nrb/beerxml/record_validators'
|
17
|
+
autoload :Style, 'nrb/beerxml/style'
|
18
|
+
autoload :Water, 'nrb/beerxml/water'
|
19
|
+
autoload :Yeast, 'nrb/beerxml/yeast'
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
defined?(BeerXML) || BeerXML = NRB::BeerXML
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'nrb/beerxml/record_validators/boolean_validator'
|
2
|
+
require 'nrb/beerxml/record_validators/percentage_validator'
|
3
|
+
module NRB; module BeerXML
|
4
|
+
class Equipment < Record
|
5
|
+
|
6
|
+
attr_accessor :batch_size # volume required
|
7
|
+
attr_accessor :boil_size # volume required
|
8
|
+
attr_accessor :boil_time # time
|
9
|
+
attr_accessor :calc_boil_volume # boolean
|
10
|
+
attr_accessor :evap_rate # percent
|
11
|
+
attr_accessor :hop_utilization # percent
|
12
|
+
attr_accessor :lauter_tun_deadspace # volume
|
13
|
+
attr_accessor :notes # string
|
14
|
+
attr_accessor :top_up_kettle # volume
|
15
|
+
attr_accessor :top_up_water # volume
|
16
|
+
attr_accessor :trub_chiller_loss # volume
|
17
|
+
attr_accessor :tun_specific_heat # float
|
18
|
+
attr_accessor :tun_volume # volume
|
19
|
+
attr_accessor :tun_weight # weight
|
20
|
+
|
21
|
+
validates :batch_size, numericality: { greater_than_or_equal_to: 0 }, presence: true
|
22
|
+
validates :boil_size, numericality: { greater_than_or_equal_to: 0 }, presence: true
|
23
|
+
validates :boil_time, numericality: { greater_than_or_equal_to: 0 }
|
24
|
+
validates :calc_boil_volume, boolean: true
|
25
|
+
validates :evap_rate, percentage: true
|
26
|
+
validates :hop_utilization, percentage: { give_110: true }
|
27
|
+
validates :lauter_tun_deadspace, numericality: { greater_than_or_equal_to: 0 }
|
28
|
+
validates :top_up_kettle, numericality: { greater_than_or_equal_to: 0 }
|
29
|
+
validates :top_up_water, numericality: { greater_than_or_equal_to: 0 }
|
30
|
+
validates :trub_chiller_loss, numericality: { greater_than_or_equal_to: 0 }
|
31
|
+
validates :tun_specific_heat, numericality: { greater_than_or_equal_to: 0 }
|
32
|
+
validates :tun_volume, numericality: { greater_than_or_equal_to: 0 }
|
33
|
+
validates :tun_weight, numericality: { greater_than_or_equal_to: 0 }
|
34
|
+
|
35
|
+
end
|
36
|
+
end; end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'nrb/beerxml/record_validators/boolean_validator' # hack so "validates percentage:" magic works
|
2
|
+
require 'nrb/beerxml/record_validators/percentage_validator' # hack so "validates percentage:" magic works
|
3
|
+
|
4
|
+
module NRB; module BeerXML
|
5
|
+
class Fermentable < Record
|
6
|
+
|
7
|
+
attr_accessor :add_after_boil # boolean
|
8
|
+
attr_accessor :amount # weight required
|
9
|
+
attr_accessor :coarse_fine_diff # percent
|
10
|
+
attr_accessor :color # float required
|
11
|
+
attr_accessor :diastatic_power # float
|
12
|
+
attr_accessor :ibu_gal_per_lb # float
|
13
|
+
attr_accessor :max_in_batch # percent
|
14
|
+
attr_accessor :moisture # percent
|
15
|
+
attr_accessor :notes # text
|
16
|
+
attr_accessor :origin # text
|
17
|
+
attr_accessor :recommend_mash # boolean
|
18
|
+
attr_accessor :supplier # text
|
19
|
+
attr_accessor :type # list required
|
20
|
+
attr_accessor :yield # percent required
|
21
|
+
|
22
|
+
validates :add_after_boil, boolean: true
|
23
|
+
validates :amount, presence: true
|
24
|
+
validates :color, presence: true
|
25
|
+
validates :type, inclusion: { in: [ "Adjunct", "Dry Extract", "Extract", "Grain", "Sugar" ] }, presence: true
|
26
|
+
validates :yield, presence: true
|
27
|
+
|
28
|
+
validates :diastatic_power, numericality: { greater_than_or_equal_to: 0 }
|
29
|
+
|
30
|
+
end
|
31
|
+
end; end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'nrb/beerxml/record_validators/percentage_validator' # hack so "validates percentage:" magic works
|
2
|
+
module NRB; module BeerXML
|
3
|
+
class Hop < Record
|
4
|
+
|
5
|
+
attr_accessor :alpha # percentage required
|
6
|
+
attr_accessor :amount # weight required
|
7
|
+
attr_accessor :beta # percentage
|
8
|
+
attr_accessor :caryophyllene # percentage
|
9
|
+
attr_accessor :cohumulone # percentage
|
10
|
+
attr_accessor :form # list
|
11
|
+
attr_accessor :hsi # percentage
|
12
|
+
attr_accessor :myrcene # percentage
|
13
|
+
attr_accessor :notes # text
|
14
|
+
attr_accessor :origin # text
|
15
|
+
attr_accessor :substitutes # text
|
16
|
+
attr_accessor :time # time required
|
17
|
+
attr_accessor :type # list
|
18
|
+
attr_accessor :use # list required
|
19
|
+
|
20
|
+
validates :alpha, presence: true, percentage: true
|
21
|
+
validates :amount, presence: true, numericality: { greater_than_or_equal_to: 0 }
|
22
|
+
validates :beta, percentage: true
|
23
|
+
validates :caryophyllene, percentage: true
|
24
|
+
validates :cohumulone, percentage: true
|
25
|
+
validates :form, inclusion: { in: %w(Leaf Pellet Plug) }
|
26
|
+
validates :hsi, percentage: true
|
27
|
+
validates :myrcene, percentage: true
|
28
|
+
validates :time, presence: true,
|
29
|
+
numericality: { greater_than_or_equal_to: 0 }
|
30
|
+
validates :type, inclusion: { in: %w(Aroma Bittering Both) }
|
31
|
+
|
32
|
+
validates :use, presence: true,
|
33
|
+
inclusion: { in: [ "Aroma", "Boil", "Dry Hop", "First Wort", "Mash" ] }
|
34
|
+
|
35
|
+
end
|
36
|
+
end; end
|
File without changes
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'nrb/beerxml/record_validators/boolean_validator'
|
2
|
+
module NRB; module BeerXML
|
3
|
+
class Mash < Record
|
4
|
+
|
5
|
+
attr_accessor :equip_adjust # boolean
|
6
|
+
attr_accessor :grain_temp # temperature required
|
7
|
+
attr_accessor :mash_steps # record set required
|
8
|
+
attr_accessor :notes # string
|
9
|
+
attr_accessor :ph # float
|
10
|
+
attr_accessor :sparge_temp # temperature
|
11
|
+
attr_accessor :tun_specific_heat # float
|
12
|
+
attr_accessor :tun_temp # temperature
|
13
|
+
attr_accessor :tun_weight # weight
|
14
|
+
|
15
|
+
validates :grain_temp, numericality: true, presence: true
|
16
|
+
validates :mash_steps, presence: true
|
17
|
+
validates :ph, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 14 }
|
18
|
+
validates :sparge_temp, numericality: true
|
19
|
+
validates :tun_specific_heat, numericality: { greater_than_or_equal_to: 0 }
|
20
|
+
validates :tun_temp, numericality: true
|
21
|
+
validates :tun_weight, numericality: { greater_than_or_equal_to: 0 }
|
22
|
+
|
23
|
+
|
24
|
+
after_initialize :initialize_mash_steps
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def initialize_mash_steps
|
29
|
+
self.mash_steps ||= RecordSet.new(record_type: :mash_step)
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end; end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module NRB; module BeerXML
|
2
|
+
class MashStep < Record
|
3
|
+
|
4
|
+
attr_accessor :end_temp # temperature
|
5
|
+
attr_accessor :infuse_amount # volume conditionally required
|
6
|
+
attr_accessor :ramp_time # time
|
7
|
+
attr_accessor :step_temp # temperature required
|
8
|
+
attr_accessor :step_time # time required
|
9
|
+
attr_accessor :type # list required
|
10
|
+
|
11
|
+
validates :end_temp, numericality: true
|
12
|
+
validates :infuse_amount, presence: { if: Proc.new { |step| step.infuse_amount_required? } }, numericality: true
|
13
|
+
validates :ramp_time, numericality: { greater_than_or_equal_to: 0 }
|
14
|
+
validates :step_temp, numericality: true, presence: true
|
15
|
+
validates :step_time, numericality: { greater_than_or_equal_to: 0 }, presence: true
|
16
|
+
validates :type, inclusion: { in: %w(Decoction Infusion Temperature) },
|
17
|
+
presence: true
|
18
|
+
|
19
|
+
def infuse_amount_required?
|
20
|
+
type == "Infusion"
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end; end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'nrb/beerxml/record_validators/boolean_validator' # hack so "validates boolean:" magic works
|
2
|
+
module NRB; module BeerXML
|
3
|
+
class Misc < Record
|
4
|
+
|
5
|
+
attr_accessor :amount # float required
|
6
|
+
attr_accessor :amount_is_weight # boolean
|
7
|
+
attr_accessor :notes # string
|
8
|
+
attr_accessor :time # time required
|
9
|
+
attr_accessor :type # list required
|
10
|
+
attr_accessor :use # list required
|
11
|
+
attr_accessor :use_for # string
|
12
|
+
|
13
|
+
validates :amount, numericality: { greater_than_or_equal_to: 0 }, presence: true
|
14
|
+
validates :amount_is_weight, boolean: true
|
15
|
+
validates :time, numericality: { greater_than_or_equal_to: 0 },
|
16
|
+
presence: true
|
17
|
+
validates :type, inclusion: { in: ["Fining", "Flavor", "Herb", "Other", "Spice", "Water Agent"] }, presence: true
|
18
|
+
validates :use, inclusion: { in: %w(Boil Bottling Mash Primary Secondary) }, presence: true
|
19
|
+
|
20
|
+
|
21
|
+
end
|
22
|
+
end; end
|
File without changes
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'nrb/beerxml/record_validators/boolean_validator' # hack so "validates boolean:" magic works
|
2
|
+
require 'nrb/beerxml/record_validators/percentage_validator' # hack so "validates percentag:" magic works
|
3
|
+
module NRB; module BeerXML
|
4
|
+
class Recipe < Record
|
5
|
+
|
6
|
+
after_initialize :set_up_record_sets
|
7
|
+
|
8
|
+
attr_accessor :age # time
|
9
|
+
attr_accessor :age_temp # temperature
|
10
|
+
attr_accessor :asst_brewer # string
|
11
|
+
attr_accessor :batch_size # volume required
|
12
|
+
attr_accessor :boil_size # volume required
|
13
|
+
attr_accessor :boil_time # time required
|
14
|
+
attr_accessor :brewer # string required
|
15
|
+
attr_accessor :carbonation # float
|
16
|
+
attr_accessor :carbonation_temp # temperature
|
17
|
+
attr_accessor :date # string
|
18
|
+
attr_accessor :efficiency # percentage conditionally required
|
19
|
+
attr_reader :equipment # equipment record
|
20
|
+
attr_accessor :fermentables # fermentables record set required
|
21
|
+
attr_accessor :fermentation_stages # integer
|
22
|
+
attr_accessor :fg # specific gravity
|
23
|
+
attr_accessor :forced_carbonation # boolean
|
24
|
+
attr_accessor :hops # hops record set required
|
25
|
+
attr_accessor :keg_priming_factor # float
|
26
|
+
attr_accessor :mash # mash profile record required
|
27
|
+
attr_accessor :miscs # miscs record set required
|
28
|
+
attr_accessor :notes # string
|
29
|
+
attr_accessor :og # specific gravity
|
30
|
+
attr_accessor :primary_age # time
|
31
|
+
attr_accessor :primary_temp # temperature
|
32
|
+
attr_accessor :priming_sugar_equiv # float
|
33
|
+
attr_accessor :priming_sugar_name # string
|
34
|
+
attr_accessor :secondary_age # time
|
35
|
+
attr_accessor :secondary_temp # temperature
|
36
|
+
attr_reader :style # style record required
|
37
|
+
attr_accessor :taste_notes # string
|
38
|
+
attr_accessor :taste_rating # float
|
39
|
+
attr_accessor :tertiary_age # time
|
40
|
+
attr_accessor :tertiary_temp # temperature
|
41
|
+
attr_accessor :type # list required
|
42
|
+
attr_accessor :waters # waters record set required
|
43
|
+
attr_accessor :yeasts # yeasts record set required
|
44
|
+
|
45
|
+
validates :age, numericality: { greater_than_or_equal_to: 0 }
|
46
|
+
validates :age_temp, numericality: true
|
47
|
+
validates :batch_size, numericality: { greater_than_or_equal_to: 0 }, presence: true
|
48
|
+
validates :boil_size, numericality: { greater_than_or_equal_to: 0 }, presence: true
|
49
|
+
validates :boil_time, numericality: { greater_than_or_equal_to: 0 }, presence: true
|
50
|
+
validates :brewer, presence: true
|
51
|
+
validates :carbonation, numericality: { greater_than_or_equal_to: 0 }
|
52
|
+
validates :carbonation_temp, numericality: true
|
53
|
+
validates :equipment, presence: true
|
54
|
+
validates :efficiency, percentage: true, presence: { if: Proc.new { |recipe| recipe.efficiency_required? } }
|
55
|
+
validates :fermentables, presence: true
|
56
|
+
validates :fermentation_stages, numericality: { only_integer: true }
|
57
|
+
validates :fg, numericality: true
|
58
|
+
validates :forced_carbonation, boolean: true
|
59
|
+
validates :hops, presence: true
|
60
|
+
validates :keg_priming_factor, numericality: true
|
61
|
+
validates :mash, presence: true
|
62
|
+
validates :miscs, presence: true
|
63
|
+
validates :og, numericality: true
|
64
|
+
validates :primary_age, numericality: { greater_than_or_equal_to: 0 }
|
65
|
+
validates :primary_temp, numericality: true
|
66
|
+
validates :priming_sugar_equiv, numericality: true
|
67
|
+
validates :secondary_age, numericality: { greater_than_or_equal_to: 0 }
|
68
|
+
validates :secondary_temp, numericality: true
|
69
|
+
validates :style, presence: true
|
70
|
+
validates :taste_rating, numericality: true
|
71
|
+
validates :tertiary_age, numericality: { greater_than_or_equal_to: 0 }
|
72
|
+
validates :tertiary_temp, numericality: true
|
73
|
+
validates :type, inclusion: { in: [ "All Grain", "Extract", "Partial Mash" ] }, presence: true
|
74
|
+
validates :waters, presence: true
|
75
|
+
validates :yeasts, presence: true
|
76
|
+
|
77
|
+
|
78
|
+
def equipment=(equipment)
|
79
|
+
restricted_assign :equipment, equipment
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
def efficiency_required?
|
84
|
+
["ALl Grain", "Partial Mash"].include?(type)
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
def set_up_record_sets
|
89
|
+
%i(fermentable hop misc water yeast).each do |record_type|
|
90
|
+
send "#{record_type}s=", RecordSet.new(record_type: record_type)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
def style=(style)
|
96
|
+
restricted_assign :style, style
|
97
|
+
end
|
98
|
+
|
99
|
+
private
|
100
|
+
|
101
|
+
def restricted_assign(type, value)
|
102
|
+
raise "Can't assign a non-#{type} to #{type} (got a #{value.record_type}" unless value.nil? || value.send("#{type}?")
|
103
|
+
instance_variable_set "@#{type}", value
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
end; end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'active_model'
|
2
|
+
module NRB; module BeerXML
|
3
|
+
class Record
|
4
|
+
include Inflector
|
5
|
+
include ActiveModel::Model
|
6
|
+
extend ActiveModel::Callbacks
|
7
|
+
extend ActiveModel::Naming
|
8
|
+
|
9
|
+
define_model_callbacks :initialize, only: :after
|
10
|
+
|
11
|
+
attr_accessor :name
|
12
|
+
attr_accessor :version
|
13
|
+
|
14
|
+
validates :name, presence: true
|
15
|
+
validates :version, presence: true, numericality: { only_integer: true }
|
16
|
+
|
17
|
+
|
18
|
+
def initialize(*args)
|
19
|
+
super
|
20
|
+
run_callbacks :initialize
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
def record_type
|
25
|
+
underscore(self.class.name.split(/::/).last).to_sym
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
def equipment?; am_a? :equipment; end
|
30
|
+
def fermentable?; am_a? :fermentable; end
|
31
|
+
def hop?; am_a? :hop; end
|
32
|
+
def mash_profile?; am_a? :mash_profile; end
|
33
|
+
def mash_step?; am_a? :mash_step; end
|
34
|
+
def misc?; am_a? :misc; end
|
35
|
+
def recipe?; am_a? :recipe; end
|
36
|
+
def style?; am_a? :style; end
|
37
|
+
def water?; am_a? :water; end
|
38
|
+
def yeast?; am_a? :yeast; end
|
39
|
+
|
40
|
+
def persisted?; false; end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def am_a?(question); record_type == question; end
|
45
|
+
|
46
|
+
end
|
47
|
+
end; end
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'nrb/beerxml/record_validators/percentage_validator'
|
2
|
+
module NRB; module BeerXML
|
3
|
+
class Style < Record
|
4
|
+
|
5
|
+
attr_accessor :abv_max # float
|
6
|
+
attr_accessor :abv_min # float
|
7
|
+
attr_accessor :carb_max # float
|
8
|
+
attr_accessor :carb_min # float
|
9
|
+
attr_accessor :category # string required
|
10
|
+
attr_accessor :category_number # string required
|
11
|
+
attr_accessor :color_max # float required
|
12
|
+
attr_accessor :color_min # float required
|
13
|
+
attr_accessor :examples # text
|
14
|
+
attr_accessor :fg_max # float required
|
15
|
+
attr_accessor :fg_min # float required
|
16
|
+
attr_accessor :ibu_max # float required
|
17
|
+
attr_accessor :ibu_min # float required
|
18
|
+
attr_accessor :ingredients # text
|
19
|
+
attr_accessor :notes # text
|
20
|
+
attr_accessor :og_max # float required
|
21
|
+
attr_accessor :og_min # float required
|
22
|
+
attr_accessor :profile # text
|
23
|
+
attr_accessor :style_guide # string required
|
24
|
+
attr_accessor :style_letter # string required
|
25
|
+
attr_accessor :type # list required
|
26
|
+
|
27
|
+
validates :abv_max, numericality: { greater_than_or_equal_to: 0 }
|
28
|
+
validates :abv_min, numericality: { greater_than_or_equal_to: 0 }
|
29
|
+
validates :carb_max, numericality: { greater_than_or_equal_to: 0 }
|
30
|
+
validates :carb_min, numericality: { greater_than_or_equal_to: 0 }
|
31
|
+
validates :category, presence: true
|
32
|
+
validates :category_number, presence: true
|
33
|
+
validates :color_max, numericality: { greater_than_or_equal_to: 0 }, presence: true
|
34
|
+
validates :color_min, numericality: { greater_than_or_equal_to: 0 }, presence: true
|
35
|
+
validates :fg_max, numericality: { greater_than_or_equal_to: 0 }, presence: true
|
36
|
+
validates :fg_min, numericality: { greater_than_or_equal_to: 0 }, presence: true
|
37
|
+
validates :ibu_max, numericality: { greater_than_or_equal_to: 0 }, presence: true
|
38
|
+
validates :ibu_min, numericality: { greater_than_or_equal_to: 0 }, presence: true
|
39
|
+
validates :og_max, numericality: { greater_than_or_equal_to: 0 }, presence: true
|
40
|
+
validates :og_min, numericality: { greater_than_or_equal_to: 0 }, presence: true
|
41
|
+
validates :style_guide, presence: true
|
42
|
+
validates :style_letter, presence: true
|
43
|
+
validates :type, inclusion: { in: %w(Ale Cider Lager Mead Mixed Wheat ) },
|
44
|
+
presence: true
|
45
|
+
|
46
|
+
end
|
47
|
+
end; end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module NRB; module BeerXML
|
2
|
+
class Water < Record
|
3
|
+
|
4
|
+
attr_accessor :amount # volume required
|
5
|
+
attr_accessor :bicarbonate # float required
|
6
|
+
attr_accessor :calcium # float required
|
7
|
+
attr_accessor :chloride # float required
|
8
|
+
attr_accessor :magnesium # float required
|
9
|
+
attr_accessor :notes # string
|
10
|
+
attr_accessor :ph # float
|
11
|
+
attr_accessor :sodium # float required
|
12
|
+
attr_accessor :sulfate # float required
|
13
|
+
|
14
|
+
validates :amount, numericality: true, presence: true
|
15
|
+
validates :bicarbonate, numericality: true, presence: true
|
16
|
+
validates :calcium, numericality: true, presence: true
|
17
|
+
validates :chloride, numericality: true, presence: true
|
18
|
+
validates :magnesium, numericality: true, presence: true
|
19
|
+
validates :ph, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 14 }
|
20
|
+
validates :sodium, numericality: true, presence: true
|
21
|
+
validates :sulfate, numericality: true, presence: true
|
22
|
+
|
23
|
+
end
|
24
|
+
end; end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'nrb/beerxml/record_validators/boolean_validator' # hack so "validates boolean:" magic works
|
2
|
+
require 'nrb/beerxml/record_validators/percentage_validator' # hack so "validates percentage:" magic works
|
3
|
+
module NRB; module BeerXML
|
4
|
+
class Yeast < Record
|
5
|
+
|
6
|
+
attr_accessor :add_to_secondary # boolean
|
7
|
+
attr_accessor :amount # float required
|
8
|
+
attr_accessor :amount_is_weight # boolean
|
9
|
+
attr_accessor :attenuation # percentage
|
10
|
+
attr_accessor :best_for # string
|
11
|
+
attr_accessor :flocculation # list
|
12
|
+
attr_accessor :form # list required
|
13
|
+
attr_accessor :laboratory # string
|
14
|
+
attr_accessor :max_reuse # integer
|
15
|
+
attr_accessor :max_temperature # temperature
|
16
|
+
attr_accessor :min_temperature # temperature
|
17
|
+
attr_accessor :notes # string
|
18
|
+
attr_accessor :product_id # string
|
19
|
+
attr_accessor :times_cultured # integer
|
20
|
+
attr_accessor :type # list required
|
21
|
+
|
22
|
+
validates :add_to_secondary, boolean: true
|
23
|
+
validates :amount, presence: { greater_than_or_equal_to: 0 }
|
24
|
+
validates :amount_is_weight, boolean: true
|
25
|
+
validates :attenuation, percentage: true
|
26
|
+
validates :flocculation, inclusion: { in: ["High", "Low", "Medium", "Very High" ] }
|
27
|
+
validates :form, presence: true, inclusion: { in: %w( Culture Dry Liquid Slant ) }
|
28
|
+
validates :max_reuse, numericality: { greater_than_or_equal_to: 0, only_integer: true }
|
29
|
+
validates :max_temperature, numericality: true
|
30
|
+
validates :min_temperature, numericality: true
|
31
|
+
validates :times_cultured, numericality: { greater_than_or_equal_to: 0, only_integer: true }
|
32
|
+
validates :type, presence: true, inclusion: { in: %w(Ale Champagne Lager Wheat Wine) }
|
33
|
+
|
34
|
+
|
35
|
+
end
|
36
|
+
end; end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nrb-beerxml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dean Brundage
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -117,26 +117,26 @@ extra_rdoc_files: []
|
|
117
117
|
files:
|
118
118
|
- README.md
|
119
119
|
- LICENSE
|
120
|
-
- lib/beerxml.rb
|
121
|
-
- lib/beerxml/builder.rb
|
122
|
-
- lib/beerxml/equipment.rb
|
123
|
-
- lib/beerxml/fermentable.rb
|
124
|
-
- lib/beerxml/hop.rb
|
125
|
-
- lib/beerxml/inflector.rb
|
126
|
-
- lib/beerxml/mash.rb
|
127
|
-
- lib/beerxml/mash_step.rb
|
128
|
-
- lib/beerxml/misc.rb
|
129
|
-
- lib/beerxml/parser.rb
|
130
|
-
- lib/beerxml/recipe.rb
|
131
|
-
- lib/beerxml/record.rb
|
132
|
-
- lib/beerxml/record_set.rb
|
133
|
-
- lib/beerxml/record_validators.rb
|
134
|
-
- lib/beerxml/record_validators/boolean_validator.rb
|
135
|
-
- lib/beerxml/record_validators/percentage_validator.rb
|
136
|
-
- lib/beerxml/style.rb
|
137
|
-
- lib/beerxml/version.rb
|
138
|
-
- lib/beerxml/water.rb
|
139
|
-
- lib/beerxml/yeast.rb
|
120
|
+
- lib/nrb/beerxml.rb
|
121
|
+
- lib/nrb/beerxml/builder.rb
|
122
|
+
- lib/nrb/beerxml/equipment.rb
|
123
|
+
- lib/nrb/beerxml/fermentable.rb
|
124
|
+
- lib/nrb/beerxml/hop.rb
|
125
|
+
- lib/nrb/beerxml/inflector.rb
|
126
|
+
- lib/nrb/beerxml/mash.rb
|
127
|
+
- lib/nrb/beerxml/mash_step.rb
|
128
|
+
- lib/nrb/beerxml/misc.rb
|
129
|
+
- lib/nrb/beerxml/parser.rb
|
130
|
+
- lib/nrb/beerxml/recipe.rb
|
131
|
+
- lib/nrb/beerxml/record.rb
|
132
|
+
- lib/nrb/beerxml/record_set.rb
|
133
|
+
- lib/nrb/beerxml/record_validators.rb
|
134
|
+
- lib/nrb/beerxml/record_validators/boolean_validator.rb
|
135
|
+
- lib/nrb/beerxml/record_validators/percentage_validator.rb
|
136
|
+
- lib/nrb/beerxml/style.rb
|
137
|
+
- lib/nrb/beerxml/version.rb
|
138
|
+
- lib/nrb/beerxml/water.rb
|
139
|
+
- lib/nrb/beerxml/yeast.rb
|
140
140
|
- spec/cases/beerxml/builder_spec.rb
|
141
141
|
- spec/cases/beerxml/equipment_spec.rb
|
142
142
|
- spec/cases/beerxml/fermentable_spec.rb
|
data/lib/beerxml.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
module NRB
|
2
|
-
module BeerXML
|
3
|
-
|
4
|
-
autoload :Builder, 'beerxml/builder'
|
5
|
-
autoload :Equipment, 'beerxml/equipment'
|
6
|
-
autoload :Fermentable, 'beerxml/fermentable'
|
7
|
-
autoload :Hop, 'beerxml/hop'
|
8
|
-
autoload :Inflector, 'beerxml/inflector'
|
9
|
-
autoload :Mash, 'beerxml/mash'
|
10
|
-
autoload :MashStep, 'beerxml/mash_step'
|
11
|
-
autoload :Misc, 'beerxml/misc'
|
12
|
-
autoload :Parser, 'beerxml/parser'
|
13
|
-
autoload :Recipe, 'beerxml/recipe'
|
14
|
-
autoload :Record, 'beerxml/record'
|
15
|
-
autoload :RecordSet, 'beerxml/record_set'
|
16
|
-
autoload :RecordValidators, 'beerxml/record_validators'
|
17
|
-
autoload :Style, 'beerxml/style'
|
18
|
-
autoload :Water, 'beerxml/water'
|
19
|
-
autoload :Yeast, 'beerxml/yeast'
|
20
|
-
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
defined?(BeerXML) || BeerXML = NRB::BeerXML
|
data/lib/beerxml/equipment.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'beerxml/record_validators/boolean_validator'
|
2
|
-
require 'beerxml/record_validators/percentage_validator'
|
3
|
-
module NRB
|
4
|
-
module BeerXML
|
5
|
-
class Equipment < Record
|
6
|
-
|
7
|
-
attr_accessor :batch_size # volume required
|
8
|
-
attr_accessor :boil_size # volume required
|
9
|
-
attr_accessor :boil_time # time
|
10
|
-
attr_accessor :calc_boil_volume # boolean
|
11
|
-
attr_accessor :evap_rate # percent
|
12
|
-
attr_accessor :hop_utilization # percent
|
13
|
-
attr_accessor :lauter_tun_deadspace # volume
|
14
|
-
attr_accessor :notes # string
|
15
|
-
attr_accessor :top_up_kettle # volume
|
16
|
-
attr_accessor :top_up_water # volume
|
17
|
-
attr_accessor :trub_chiller_loss # volume
|
18
|
-
attr_accessor :tun_specific_heat # float
|
19
|
-
attr_accessor :tun_volume # volume
|
20
|
-
attr_accessor :tun_weight # weight
|
21
|
-
|
22
|
-
validates :batch_size, numericality: { greater_than_or_equal_to: 0 }, presence: true
|
23
|
-
validates :boil_size, numericality: { greater_than_or_equal_to: 0 }, presence: true
|
24
|
-
validates :boil_time, numericality: { greater_than_or_equal_to: 0 }
|
25
|
-
validates :calc_boil_volume, boolean: true
|
26
|
-
validates :evap_rate, percentage: true
|
27
|
-
validates :hop_utilization, percentage: { give_110: true }
|
28
|
-
validates :lauter_tun_deadspace, numericality: { greater_than_or_equal_to: 0 }
|
29
|
-
validates :top_up_kettle, numericality: { greater_than_or_equal_to: 0 }
|
30
|
-
validates :top_up_water, numericality: { greater_than_or_equal_to: 0 }
|
31
|
-
validates :trub_chiller_loss, numericality: { greater_than_or_equal_to: 0 }
|
32
|
-
validates :tun_specific_heat, numericality: { greater_than_or_equal_to: 0 }
|
33
|
-
validates :tun_volume, numericality: { greater_than_or_equal_to: 0 }
|
34
|
-
validates :tun_weight, numericality: { greater_than_or_equal_to: 0 }
|
35
|
-
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
data/lib/beerxml/fermentable.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'beerxml/record_validators/boolean_validator' # hack so "validates percentage:" magic works
|
2
|
-
require 'beerxml/record_validators/percentage_validator' # hack so "validates percentage:" magic works
|
3
|
-
|
4
|
-
module NRB
|
5
|
-
module BeerXML
|
6
|
-
class Fermentable < Record
|
7
|
-
|
8
|
-
attr_accessor :add_after_boil # boolean
|
9
|
-
attr_accessor :amount # weight required
|
10
|
-
attr_accessor :coarse_fine_diff # percent
|
11
|
-
attr_accessor :color # float required
|
12
|
-
attr_accessor :diastatic_power # float
|
13
|
-
attr_accessor :ibu_gal_per_lb # float
|
14
|
-
attr_accessor :max_in_batch # percent
|
15
|
-
attr_accessor :moisture # percent
|
16
|
-
attr_accessor :notes # text
|
17
|
-
attr_accessor :origin # text
|
18
|
-
attr_accessor :recommend_mash # boolean
|
19
|
-
attr_accessor :supplier # text
|
20
|
-
attr_accessor :type # list required
|
21
|
-
attr_accessor :yield # percent required
|
22
|
-
|
23
|
-
validates :add_after_boil, boolean: true
|
24
|
-
validates :amount, presence: true
|
25
|
-
validates :color, presence: true
|
26
|
-
validates :type, inclusion: { in: [ "Adjunct", "Dry Extract", "Extract", "Grain", "Sugar" ] }, presence: true
|
27
|
-
validates :yield, presence: true
|
28
|
-
|
29
|
-
validates :diastatic_power, numericality: { greater_than_or_equal_to: 0 }
|
30
|
-
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
data/lib/beerxml/hop.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'beerxml/record_validators/percentage_validator' # hack so "validates percentage:" magic works
|
2
|
-
module NRB
|
3
|
-
module BeerXML
|
4
|
-
class Hop < Record
|
5
|
-
|
6
|
-
attr_accessor :alpha # percentage required
|
7
|
-
attr_accessor :amount # weight required
|
8
|
-
attr_accessor :beta # percentage
|
9
|
-
attr_accessor :caryophyllene # percentage
|
10
|
-
attr_accessor :cohumulone # percentage
|
11
|
-
attr_accessor :form # list
|
12
|
-
attr_accessor :hsi # percentage
|
13
|
-
attr_accessor :myrcene # percentage
|
14
|
-
attr_accessor :notes # text
|
15
|
-
attr_accessor :origin # text
|
16
|
-
attr_accessor :substitutes # text
|
17
|
-
attr_accessor :time # time required
|
18
|
-
attr_accessor :type # list
|
19
|
-
attr_accessor :use # list required
|
20
|
-
|
21
|
-
validates :alpha, presence: true, percentage: true
|
22
|
-
validates :amount, presence: true, numericality: { greater_than_or_equal_to: 0 }
|
23
|
-
validates :beta, percentage: true
|
24
|
-
validates :caryophyllene, percentage: true
|
25
|
-
validates :cohumulone, percentage: true
|
26
|
-
validates :form, inclusion: { in: %w(Leaf Pellet Plug) }
|
27
|
-
validates :hsi, percentage: true
|
28
|
-
validates :myrcene, percentage: true
|
29
|
-
validates :time, presence: true,
|
30
|
-
numericality: { greater_than_or_equal_to: 0 }
|
31
|
-
validates :type, inclusion: { in: %w(Aroma Bittering Both) }
|
32
|
-
|
33
|
-
validates :use, presence: true,
|
34
|
-
inclusion: { in: [ "Aroma", "Boil", "Dry Hop", "First Wort", "Mash" ] }
|
35
|
-
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
data/lib/beerxml/mash.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
require 'beerxml/record_validators/boolean_validator'
|
2
|
-
module NRB
|
3
|
-
module BeerXML
|
4
|
-
class Mash < Record
|
5
|
-
|
6
|
-
attr_accessor :equip_adjust # boolean
|
7
|
-
attr_accessor :grain_temp # temperature required
|
8
|
-
attr_accessor :mash_steps # record set required
|
9
|
-
attr_accessor :notes # string
|
10
|
-
attr_accessor :ph # float
|
11
|
-
attr_accessor :sparge_temp # temperature
|
12
|
-
attr_accessor :tun_specific_heat # float
|
13
|
-
attr_accessor :tun_temp # temperature
|
14
|
-
attr_accessor :tun_weight # weight
|
15
|
-
|
16
|
-
validates :grain_temp, numericality: true, presence: true
|
17
|
-
validates :mash_steps, presence: true
|
18
|
-
validates :ph, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 14 }
|
19
|
-
validates :sparge_temp, numericality: true
|
20
|
-
validates :tun_specific_heat, numericality: { greater_than_or_equal_to: 0 }
|
21
|
-
validates :tun_temp, numericality: true
|
22
|
-
validates :tun_weight, numericality: { greater_than_or_equal_to: 0 }
|
23
|
-
|
24
|
-
|
25
|
-
after_initialize :initialize_mash_steps
|
26
|
-
|
27
|
-
private
|
28
|
-
|
29
|
-
def initialize_mash_steps
|
30
|
-
self.mash_steps ||= RecordSet.new(record_type: :mash_step)
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
data/lib/beerxml/mash_step.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
module NRB
|
2
|
-
module BeerXML
|
3
|
-
class MashStep < Record
|
4
|
-
|
5
|
-
attr_accessor :end_temp # temperature
|
6
|
-
attr_accessor :infuse_amount # volume conditionally required
|
7
|
-
attr_accessor :ramp_time # time
|
8
|
-
attr_accessor :step_temp # temperature required
|
9
|
-
attr_accessor :step_time # time required
|
10
|
-
attr_accessor :type # list required
|
11
|
-
|
12
|
-
validates :end_temp, numericality: true
|
13
|
-
validates :infuse_amount, presence: { if: Proc.new { |step| step.infuse_amount_required? } }, numericality: true
|
14
|
-
validates :ramp_time, numericality: { greater_than_or_equal_to: 0 }
|
15
|
-
validates :step_temp, numericality: true, presence: true
|
16
|
-
validates :step_time, numericality: { greater_than_or_equal_to: 0 }, presence: true
|
17
|
-
validates :type, inclusion: { in: %w(Decoction Infusion Temperature) },
|
18
|
-
presence: true
|
19
|
-
|
20
|
-
def infuse_amount_required?
|
21
|
-
type == "Infusion"
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
data/lib/beerxml/misc.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'beerxml/record_validators/boolean_validator' # hack so "validates boolean:" magic works
|
2
|
-
module NRB
|
3
|
-
module BeerXML
|
4
|
-
class Misc < Record
|
5
|
-
|
6
|
-
attr_accessor :amount # float required
|
7
|
-
attr_accessor :amount_is_weight # boolean
|
8
|
-
attr_accessor :notes # string
|
9
|
-
attr_accessor :time # time required
|
10
|
-
attr_accessor :type # list required
|
11
|
-
attr_accessor :use # list required
|
12
|
-
attr_accessor :use_for # string
|
13
|
-
|
14
|
-
validates :amount, numericality: { greater_than_or_equal_to: 0 }, presence: true
|
15
|
-
validates :amount_is_weight, boolean: true
|
16
|
-
validates :time, numericality: { greater_than_or_equal_to: 0 },
|
17
|
-
presence: true
|
18
|
-
validates :type, inclusion: { in: ["Fining", "Flavor", "Herb", "Other", "Spice", "Water Agent"] }, presence: true
|
19
|
-
validates :use, inclusion: { in: %w(Boil Bottling Mash Primary Secondary) }, presence: true
|
20
|
-
|
21
|
-
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
data/lib/beerxml/recipe.rb
DELETED
@@ -1,109 +0,0 @@
|
|
1
|
-
require 'beerxml/record_validators/boolean_validator' # hack so "validates boolean:" magic works
|
2
|
-
require 'beerxml/record_validators/percentage_validator' # hack so "validates percentag:" magic works
|
3
|
-
module NRB
|
4
|
-
module BeerXML
|
5
|
-
class Recipe < Record
|
6
|
-
|
7
|
-
after_initialize :set_up_record_sets
|
8
|
-
|
9
|
-
attr_accessor :age # time
|
10
|
-
attr_accessor :age_temp # temperature
|
11
|
-
attr_accessor :asst_brewer # string
|
12
|
-
attr_accessor :batch_size # volume required
|
13
|
-
attr_accessor :boil_size # volume required
|
14
|
-
attr_accessor :boil_time # time required
|
15
|
-
attr_accessor :brewer # string required
|
16
|
-
attr_accessor :carbonation # float
|
17
|
-
attr_accessor :carbonation_temp # temperature
|
18
|
-
attr_accessor :date # string
|
19
|
-
attr_accessor :efficiency # percentage conditionally required
|
20
|
-
attr_reader :equipment # equipment record
|
21
|
-
attr_accessor :fermentables # fermentables record set required
|
22
|
-
attr_accessor :fermentation_stages # integer
|
23
|
-
attr_accessor :fg # specific gravity
|
24
|
-
attr_accessor :forced_carbonation # boolean
|
25
|
-
attr_accessor :hops # hops record set required
|
26
|
-
attr_accessor :keg_priming_factor # float
|
27
|
-
attr_accessor :mash # mash profile record required
|
28
|
-
attr_accessor :miscs # miscs record set required
|
29
|
-
attr_accessor :notes # string
|
30
|
-
attr_accessor :og # specific gravity
|
31
|
-
attr_accessor :primary_age # time
|
32
|
-
attr_accessor :primary_temp # temperature
|
33
|
-
attr_accessor :priming_sugar_equiv # float
|
34
|
-
attr_accessor :priming_sugar_name # string
|
35
|
-
attr_accessor :secondary_age # time
|
36
|
-
attr_accessor :secondary_temp # temperature
|
37
|
-
attr_reader :style # style record required
|
38
|
-
attr_accessor :taste_notes # string
|
39
|
-
attr_accessor :taste_rating # float
|
40
|
-
attr_accessor :tertiary_age # time
|
41
|
-
attr_accessor :tertiary_temp # temperature
|
42
|
-
attr_accessor :type # list required
|
43
|
-
attr_accessor :waters # waters record set required
|
44
|
-
attr_accessor :yeasts # yeasts record set required
|
45
|
-
|
46
|
-
validates :age, numericality: { greater_than_or_equal_to: 0 }
|
47
|
-
validates :age_temp, numericality: true
|
48
|
-
validates :batch_size, numericality: { greater_than_or_equal_to: 0 }, presence: true
|
49
|
-
validates :boil_size, numericality: { greater_than_or_equal_to: 0 }, presence: true
|
50
|
-
validates :boil_time, numericality: { greater_than_or_equal_to: 0 }, presence: true
|
51
|
-
validates :brewer, presence: true
|
52
|
-
validates :carbonation, numericality: { greater_than_or_equal_to: 0 }
|
53
|
-
validates :carbonation_temp, numericality: true
|
54
|
-
validates :equipment, presence: true
|
55
|
-
validates :efficiency, percentage: true, presence: { if: Proc.new { |recipe| recipe.efficiency_required? } }
|
56
|
-
validates :fermentables, presence: true
|
57
|
-
validates :fermentation_stages, numericality: { only_integer: true }
|
58
|
-
validates :fg, numericality: true
|
59
|
-
validates :forced_carbonation, boolean: true
|
60
|
-
validates :hops, presence: true
|
61
|
-
validates :keg_priming_factor, numericality: true
|
62
|
-
validates :mash, presence: true
|
63
|
-
validates :miscs, presence: true
|
64
|
-
validates :og, numericality: true
|
65
|
-
validates :primary_age, numericality: { greater_than_or_equal_to: 0 }
|
66
|
-
validates :primary_temp, numericality: true
|
67
|
-
validates :priming_sugar_equiv, numericality: true
|
68
|
-
validates :secondary_age, numericality: { greater_than_or_equal_to: 0 }
|
69
|
-
validates :secondary_temp, numericality: true
|
70
|
-
validates :style, presence: true
|
71
|
-
validates :taste_rating, numericality: true
|
72
|
-
validates :tertiary_age, numericality: { greater_than_or_equal_to: 0 }
|
73
|
-
validates :tertiary_temp, numericality: true
|
74
|
-
validates :type, inclusion: { in: [ "All Grain", "Extract", "Partial Mash" ] }, presence: true
|
75
|
-
validates :waters, presence: true
|
76
|
-
validates :yeasts, presence: true
|
77
|
-
|
78
|
-
|
79
|
-
def equipment=(equipment)
|
80
|
-
restricted_assign :equipment, equipment
|
81
|
-
end
|
82
|
-
|
83
|
-
|
84
|
-
def efficiency_required?
|
85
|
-
["ALl Grain", "Partial Mash"].include?(type)
|
86
|
-
end
|
87
|
-
|
88
|
-
|
89
|
-
def set_up_record_sets
|
90
|
-
%i(fermentable hop misc water yeast).each do |record_type|
|
91
|
-
send "#{record_type}s=", RecordSet.new(record_type: record_type)
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
|
96
|
-
def style=(style)
|
97
|
-
restricted_assign :style, style
|
98
|
-
end
|
99
|
-
|
100
|
-
private
|
101
|
-
|
102
|
-
def restricted_assign(type, value)
|
103
|
-
raise "Can't assign a non-#{type} to #{type} (got a #{value.record_type}" unless value.nil? || value.send("#{type}?")
|
104
|
-
instance_variable_set "@#{type}", value
|
105
|
-
end
|
106
|
-
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
data/lib/beerxml/record.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'active_model'
|
2
|
-
module NRB
|
3
|
-
module BeerXML
|
4
|
-
class Record
|
5
|
-
include Inflector
|
6
|
-
include ActiveModel::Model
|
7
|
-
extend ActiveModel::Callbacks
|
8
|
-
extend ActiveModel::Naming
|
9
|
-
|
10
|
-
define_model_callbacks :initialize, only: :after
|
11
|
-
|
12
|
-
attr_accessor :name
|
13
|
-
attr_accessor :version
|
14
|
-
|
15
|
-
validates :name, presence: true
|
16
|
-
validates :version, presence: true, numericality: { only_integer: true }
|
17
|
-
|
18
|
-
|
19
|
-
def initialize(*args)
|
20
|
-
super
|
21
|
-
run_callbacks :initialize
|
22
|
-
end
|
23
|
-
|
24
|
-
|
25
|
-
def record_type
|
26
|
-
underscore(self.class.name.split(/::/).last).to_sym
|
27
|
-
end
|
28
|
-
|
29
|
-
|
30
|
-
def equipment?; am_a? :equipment; end
|
31
|
-
def fermentable?; am_a? :fermentable; end
|
32
|
-
def hop?; am_a? :hop; end
|
33
|
-
def mash_profile?; am_a? :mash_profile; end
|
34
|
-
def mash_step?; am_a? :mash_step; end
|
35
|
-
def misc?; am_a? :misc; end
|
36
|
-
def recipe?; am_a? :recipe; end
|
37
|
-
def style?; am_a? :style; end
|
38
|
-
def water?; am_a? :water; end
|
39
|
-
def yeast?; am_a? :yeast; end
|
40
|
-
|
41
|
-
def persisted?; false; end
|
42
|
-
|
43
|
-
private
|
44
|
-
|
45
|
-
def am_a?(question); record_type == question; end
|
46
|
-
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
data/lib/beerxml/style.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'beerxml/record_validators/percentage_validator'
|
2
|
-
module NRB
|
3
|
-
module BeerXML
|
4
|
-
class Style < Record
|
5
|
-
|
6
|
-
attr_accessor :abv_max # float
|
7
|
-
attr_accessor :abv_min # float
|
8
|
-
attr_accessor :carb_max # float
|
9
|
-
attr_accessor :carb_min # float
|
10
|
-
attr_accessor :category # string required
|
11
|
-
attr_accessor :category_number # string required
|
12
|
-
attr_accessor :color_max # float required
|
13
|
-
attr_accessor :color_min # float required
|
14
|
-
attr_accessor :examples # text
|
15
|
-
attr_accessor :fg_max # float required
|
16
|
-
attr_accessor :fg_min # float required
|
17
|
-
attr_accessor :ibu_max # float required
|
18
|
-
attr_accessor :ibu_min # float required
|
19
|
-
attr_accessor :ingredients # text
|
20
|
-
attr_accessor :notes # text
|
21
|
-
attr_accessor :og_max # float required
|
22
|
-
attr_accessor :og_min # float required
|
23
|
-
attr_accessor :profile # text
|
24
|
-
attr_accessor :style_guide # string required
|
25
|
-
attr_accessor :style_letter # string required
|
26
|
-
attr_accessor :type # list required
|
27
|
-
|
28
|
-
validates :abv_max, numericality: { greater_than_or_equal_to: 0 }
|
29
|
-
validates :abv_min, numericality: { greater_than_or_equal_to: 0 }
|
30
|
-
validates :carb_max, numericality: { greater_than_or_equal_to: 0 }
|
31
|
-
validates :carb_min, numericality: { greater_than_or_equal_to: 0 }
|
32
|
-
validates :category, presence: true
|
33
|
-
validates :category_number, presence: true
|
34
|
-
validates :color_max, numericality: { greater_than_or_equal_to: 0 }, presence: true
|
35
|
-
validates :color_min, numericality: { greater_than_or_equal_to: 0 }, presence: true
|
36
|
-
validates :fg_max, numericality: { greater_than_or_equal_to: 0 }, presence: true
|
37
|
-
validates :fg_min, numericality: { greater_than_or_equal_to: 0 }, presence: true
|
38
|
-
validates :ibu_max, numericality: { greater_than_or_equal_to: 0 }, presence: true
|
39
|
-
validates :ibu_min, numericality: { greater_than_or_equal_to: 0 }, presence: true
|
40
|
-
validates :og_max, numericality: { greater_than_or_equal_to: 0 }, presence: true
|
41
|
-
validates :og_min, numericality: { greater_than_or_equal_to: 0 }, presence: true
|
42
|
-
validates :style_guide, presence: true
|
43
|
-
validates :style_letter, presence: true
|
44
|
-
validates :type, inclusion: { in: %w(Ale Cider Lager Mead Mixed Wheat ) },
|
45
|
-
presence: true
|
46
|
-
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
data/lib/beerxml/version.rb
DELETED
data/lib/beerxml/water.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
module NRB
|
2
|
-
module BeerXML
|
3
|
-
class Water < Record
|
4
|
-
|
5
|
-
attr_accessor :amount # volume required
|
6
|
-
attr_accessor :bicarbonate # float required
|
7
|
-
attr_accessor :calcium # float required
|
8
|
-
attr_accessor :chloride # float required
|
9
|
-
attr_accessor :magnesium # float required
|
10
|
-
attr_accessor :notes # string
|
11
|
-
attr_accessor :ph # float
|
12
|
-
attr_accessor :sodium # float required
|
13
|
-
attr_accessor :sulfate # float required
|
14
|
-
|
15
|
-
validates :amount, numericality: true, presence: true
|
16
|
-
validates :bicarbonate, numericality: true, presence: true
|
17
|
-
validates :calcium, numericality: true, presence: true
|
18
|
-
validates :chloride, numericality: true, presence: true
|
19
|
-
validates :magnesium, numericality: true, presence: true
|
20
|
-
validates :ph, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 14 }
|
21
|
-
validates :sodium, numericality: true, presence: true
|
22
|
-
validates :sulfate, numericality: true, presence: true
|
23
|
-
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
data/lib/beerxml/yeast.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'beerxml/record_validators/boolean_validator' # hack so "validates boolean:" magic works
|
2
|
-
require 'beerxml/record_validators/percentage_validator' # hack so "validates percentage:" magic works
|
3
|
-
module NRB
|
4
|
-
module BeerXML
|
5
|
-
class Yeast < Record
|
6
|
-
|
7
|
-
attr_accessor :add_to_secondary # boolean
|
8
|
-
attr_accessor :amount # float required
|
9
|
-
attr_accessor :amount_is_weight # boolean
|
10
|
-
attr_accessor :attenuation # percentage
|
11
|
-
attr_accessor :best_for # string
|
12
|
-
attr_accessor :flocculation # list
|
13
|
-
attr_accessor :form # list required
|
14
|
-
attr_accessor :laboratory # string
|
15
|
-
attr_accessor :max_reuse # integer
|
16
|
-
attr_accessor :max_temperature # temperature
|
17
|
-
attr_accessor :min_temperature # temperature
|
18
|
-
attr_accessor :notes # string
|
19
|
-
attr_accessor :product_id # string
|
20
|
-
attr_accessor :times_cultured # integer
|
21
|
-
attr_accessor :type # list required
|
22
|
-
|
23
|
-
validates :add_to_secondary, boolean: true
|
24
|
-
validates :amount, presence: { greater_than_or_equal_to: 0 }
|
25
|
-
validates :amount_is_weight, boolean: true
|
26
|
-
validates :attenuation, percentage: true
|
27
|
-
validates :flocculation, inclusion: { in: ["High", "Low", "Medium", "Very High" ] }
|
28
|
-
validates :form, presence: true, inclusion: { in: %w( Culture Dry Liquid Slant ) }
|
29
|
-
validates :max_reuse, numericality: { greater_than_or_equal_to: 0, only_integer: true }
|
30
|
-
validates :max_temperature, numericality: true
|
31
|
-
validates :min_temperature, numericality: true
|
32
|
-
validates :times_cultured, numericality: { greater_than_or_equal_to: 0, only_integer: true }
|
33
|
-
validates :type, presence: true, inclusion: { in: %w(Ale Champagne Lager Wheat Wine) }
|
34
|
-
|
35
|
-
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|