Class: AhoyCaptain::FiltersConfiguration

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFiltersConfiguration

Returns a new instance of FiltersConfiguration.



47
48
49
# File 'lib/ahoy_captain/filters_configuration.rb', line 47

def initialize
  @registry = {}
end

Class Method Details

.load_defaultObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/ahoy_captain/filters_configuration.rb', line 6

def self.load_default
  new.tap do |config|
    config.register("Page") do
      filter column: :route, label: "Route", url: :filters_actions_path, predicates: [:in, :not_in]
      filter column: :entry_page, label: "Entry Page", url: :filters_entry_pages_path, predicates: [:in, :not_in]
      filter column: :exit_page, label: "Exit Page", url: :filters_exit_pages_path, predicates: [:in, :not_in]
    end

    config.register("Geography") do
      filter column: :country, label: "Country", url: :filters_locations_countries_path, predicates: [:in, :not_in]
      filter column: :region, label: "Region", url: :filters_locations_regions_path, predicates: [:in, :not_in]
      filter column: :city, label: "City", url: :filters_locations_cities_path, predicates: [:in, :not_in]
    end

    config.register("Source") do
      filter column: :referring_domain, label: "Source", url: :filters_sources_path, predicates: [:in, :not_in]
    end

    config.register("Screen size") do
      filter column: :device_type, label: "Screen size", url: :filters_screens_path, predicates: [:in, :not_in]
    end

    config.register("Operating System") do
      filter column: :os, label: "OS Name", url: :filters_names_path, predicates: [:in, :not_in]
      filter column: :os_version, label: "OS Version", url: :filters_versions_path, predicates: [:in, :not_in]
    end

    config.register("UTM Tags") do
      filter column: :utm_medium, label: "UTM Medium", url: :filters_utm_mediums_path, predicates: [:in, :not_in, :cont]
      filter column: :utm_source, label: "UTM Source", url: :filters_utm_sources_path, predicates: [:in, :not_in, :cont]
      filter column: :utm_campaign, label: "UTM Campaign", url: :filters_utm_campaigns_path, predicates: [:in, :not_in, :cont]
      filter column: :utm_term, label: "UTM Term", url: :filters_utm_terms_path, predicates: [:in, :not_in, :cont]
      filter column: :utm_content, label: "UTM Content", url: :filters_utm_contents_path, predicates: [:in, :not_in, :cont]
    end

    config.register("Goal") do
      filter column: :goal, label: "Goal", url: :filters_goals_path, predicates: [:in]
    end
  end
end

Instance Method Details

#[](val) ⇒ Object



57
58
59
# File 'lib/ahoy_captain/filters_configuration.rb', line 57

def [](val)
  @registry[val]
end

#delete(name) ⇒ Object



61
62
63
# File 'lib/ahoy_captain/filters_configuration.rb', line 61

def delete(name)
  @registry.delete(name)
end

#detect(&block) ⇒ Object



73
74
75
# File 'lib/ahoy_captain/filters_configuration.rb', line 73

def detect(&block)
  @registry.detect(&block)
end

#each(&block) ⇒ Object



69
70
71
# File 'lib/ahoy_captain/filters_configuration.rb', line 69

def each(&block)
  @registry.each(&block)
end

#register(label, &block) ⇒ Object



51
52
53
54
55
# File 'lib/ahoy_captain/filters_configuration.rb', line 51

def register(label, &block)
  item = FilterConfiguration::FilterCollection.new(label)
  item.instance_exec(&block)
  @registry[label] = item
end

#resetObject



65
66
67
# File 'lib/ahoy_captain/filters_configuration.rb', line 65

def reset
  @registry = {}
end