Class: OpenStax::Api::Constraints

Inherits:
Object
  • Object
show all
Defined in:
lib/openstax/api/constraints.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Constraints

Returns a new instance of Constraints.



6
7
8
9
# File 'lib/openstax/api/constraints.rb', line 6

def initialize(options)
  @version = options[:version]
  @default = options[:default]
end

Instance Method Details

#api_accept_headerObject



11
12
13
# File 'lib/openstax/api/constraints.rb', line 11

def api_accept_header
  "application/vnd.openstax.#{@version.to_s}"
end

#matches?(req) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/openstax/api/constraints.rb', line 15

def matches?(req)
  !!(@default || req.headers['Accept'].try(:include?, api_accept_header))
end