Class: PodcastAgent

Inherits:
Object
  • Object
show all
Defined in:
lib/podcast_agent.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, type:, user_agent:) ⇒ PodcastAgent

Returns a new instance of PodcastAgent.



7
8
9
10
11
12
13
# File 'lib/podcast_agent.rb', line 7

def initialize(name:, type:, user_agent:)
  @name  = name
  @type = type
  @user_agent = user_agent
  @browser    = user_agent.browser
  @platform   = user_agent.platform
end

Instance Attribute Details

#browserObject (readonly)

Returns the value of attribute browser.



5
6
7
# File 'lib/podcast_agent.rb', line 5

def browser
  @browser
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/podcast_agent.rb', line 5

def name
  @name
end

#platformObject (readonly)

Returns the value of attribute platform.



5
6
7
# File 'lib/podcast_agent.rb', line 5

def platform
  @platform
end

#typeObject (readonly)

Returns the value of attribute type.



5
6
7
# File 'lib/podcast_agent.rb', line 5

def type
  @type
end

Class Method Details

.databaseObject



22
23
24
# File 'lib/podcast_agent.rb', line 22

def self.database
  @database ||= YAML.load_file('lib/data/podcast_agents.yml')
end

.find_by(user_agent_string:) ⇒ Object



15
16
17
18
19
20
# File 'lib/podcast_agent.rb', line 15

def self.find_by(user_agent_string:)
  entry = database.find do |attrs|
    user_agent_string =~ Regexp.new(attrs['regex'])
  end
  new(name: entry['name'], type: entry['type'], user_agent: UserAgent.parse(user_agent_string)) if entry
end