Class: AcceptableApi::Mappers
- Inherits:
-
Object
- Object
- AcceptableApi::Mappers
- Includes:
- Enumerable
- Defined in:
- lib/acceptable_api/mappers.rb
Instance Method Summary collapse
- #<<(mapper) ⇒ Object
- #each(&block) ⇒ Object
- #from(what) ⇒ Object
-
#initialize(mappers = []) ⇒ Mappers
constructor
A new instance of Mappers.
- #mime_types ⇒ Object
- #to(accepts) ⇒ Object
Constructor Details
#initialize(mappers = []) ⇒ Mappers
Returns a new instance of Mappers.
6 7 8 |
# File 'lib/acceptable_api/mappers.rb', line 6 def initialize mappers = [] self.mappers = mappers end |
Instance Method Details
#<<(mapper) ⇒ Object
10 11 12 |
# File 'lib/acceptable_api/mappers.rb', line 10 def << mapper mappers << mapper end |
#each(&block) ⇒ Object
31 32 33 |
# File 'lib/acceptable_api/mappers.rb', line 31 def each &block mappers.each &block end |
#from(what) ⇒ Object
14 15 16 |
# File 'lib/acceptable_api/mappers.rb', line 14 def from what Mappers.new mappers.select { |m| m.from? what } end |
#mime_types ⇒ Object
27 28 29 |
# File 'lib/acceptable_api/mappers.rb', line 27 def mime_types mappers.map { |m| m.to }.sort.uniq end |
#to(accepts) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/acceptable_api/mappers.rb', line 18 def to accepts acceptable_mime_types = accepts.order mime_types mapper = acceptable_mime_types.map { |mt| mappers.detect { |m| m.to? mt } }[0] return mapper unless mapper.nil? MissingMapper.instance end |