Class: Protocol::Media::Set::Builder
- Inherits:
-
Object
- Object
- Protocol::Media::Set::Builder
- Defined in:
- lib/protocol/media/set.rb
Overview
Incrementally constructs an immutable media set.
Instance Method Summary collapse
-
#add(media_range) ⇒ Object
(also: #<<)
Add a media range to the set under construction.
-
#build ⇒ Object
Compile the current ranges into an immutable set.
-
#initialize ⇒ Builder
constructor
Initialize an empty media set builder.
Constructor Details
#initialize ⇒ Builder
Initialize an empty media set builder.
68 69 70 |
# File 'lib/protocol/media/set.rb', line 68 def initialize @types = {} end |
Instance Method Details
#add(media_range) ⇒ Object Also known as: <<
Add a media range to the set under construction.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/protocol/media/set.rb', line 75 def add(media_range) if @types.instance_of?(Any) return self end media_range = Range.for(media_range) media_range = Range.build(media_range.type, media_range.subtype) type = media_range.type.freeze subtype = media_range.subtype.freeze if type == "*" @types = ANY elsif subtype == "*" @types[type] = ANY elsif subtypes = @types[type] unless subtypes.instance_of?(Any) subtypes.add(subtype) end else @types[type] = ::Set.new([subtype]) end return self end |