Class: Android::Manifest::IntentFilter
- Inherits:
-
Object
- Object
- Android::Manifest::IntentFilter
- Defined in:
- lib/android/manifest.rb
Overview
intent-filter element in components
Direct Known Subclasses
Defined Under Namespace
Classes: Action, Category, Data
Constant Summary collapse
- TYPES =
filter types (action is required, category and data are optional)
['action', 'category', 'data']
- CATEGORY_BROWSABLE =
browsable of category
'android.intent.category.BROWSABLE'
Instance Attribute Summary collapse
-
#actions ⇒ IntentFilter::Action
readonly
Intent-filter actions.
-
#activity ⇒ IntentFilter::Data
readonly
Intent-filter data.
-
#categories ⇒ IntentFilter::Category
readonly
Intent-filter categories.
-
#data ⇒ IntentFilter::Data
readonly
Intent-filter data.
Class Method Summary collapse
-
.valid?(filter) ⇒ Boolean
the element is valid IntentFilter element or not.
Instance Method Summary collapse
-
#browsable? ⇒ Boolean
the browsable category vaild or not.
-
#deep_links ⇒ Array<String>
All data elements.
-
#deep_links? ⇒ Boolean
the deep links exists with http or https in data element or not.
-
#empty? ⇒ Boolean
Returns true if self contains no [IntentFilter::Action] elements.
- #exist?(name, type: nil) ⇒ Boolean
-
#initialize(filter) ⇒ IntentFilter
constructor
A new instance of IntentFilter.
-
#schemes ⇒ Array<String>
All data elements.
-
#schemes? ⇒ Boolean
the deep links exists with non-http or non-https in data element or not.
Constructor Details
#initialize(filter) ⇒ IntentFilter
Returns a new instance of IntentFilter.
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/android/manifest.rb', line 161 def initialize(filter) @activity = filter.parent @actions = [] @categories = [] @data = [] filter.elements.each do |element| type = element.name.downcase next unless TYPES.include?(type) case type when 'action' @actions << Action.new(element) when 'category' @categories << Category.new(element) when 'data' @data << Data.new(element) end end end |
Instance Attribute Details
#actions ⇒ IntentFilter::Action (readonly)
Returns intent-filter actions.
153 154 155 |
# File 'lib/android/manifest.rb', line 153 def actions @actions end |
#activity ⇒ IntentFilter::Data (readonly)
Returns intent-filter data.
159 160 161 |
# File 'lib/android/manifest.rb', line 159 def activity @activity end |
#categories ⇒ IntentFilter::Category (readonly)
Returns intent-filter categories.
155 156 157 |
# File 'lib/android/manifest.rb', line 155 def categories @categories end |
#data ⇒ IntentFilter::Data (readonly)
Returns intent-filter data.
157 158 159 |
# File 'lib/android/manifest.rb', line 157 def data @data end |
Class Method Details
.valid?(filter) ⇒ Boolean
the element is valid IntentFilter element or not
144 145 146 147 148 149 150 |
# File 'lib/android/manifest.rb', line 144 def self.valid?(filter) filter&.elements&.any? do |elem| TYPES.include?(elem&.name&.downcase) end rescue false end |
Instance Method Details
#browsable? ⇒ Boolean
the browsable category vaild or not
248 249 250 |
# File 'lib/android/manifest.rb', line 248 def browsable? exist?(CATEGORY_BROWSABLE) end |
#deep_links ⇒ Array<String>
return empty array when the manifest include no http or https scheme of data
Returns all data elements.
212 213 214 215 216 217 218 |
# File 'lib/android/manifest.rb', line 212 def deep_links return unless deep_links? data.select {|d| !d.host.nil? } .map { |d| d.host } .uniq end |
#deep_links? ⇒ Boolean
the deep links exists with http or https in data element or not
223 224 225 |
# File 'lib/android/manifest.rb', line 223 def deep_links? browsable? && data.any? { |d| ['http', 'https'].include?(d.scheme) } end |
#empty? ⇒ Boolean
Returns true if self contains no [IntentFilter::Action] elements.
184 185 186 |
# File 'lib/android/manifest.rb', line 184 def empty? @actions.empty? end |
#exist?(name, type: nil) ⇒ Boolean
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/android/manifest.rb', line 188 def exist?(name, type: nil) if type.to_s.empty? && !name.start_with?('android.intent.') raise 'Fill type or use correct name' end type ||= name.split('.')[2] raise 'Not found type' unless TYPES.include?(type) method_name = case type when 'action' :actions when 'category' :categories when 'data' :data end values = send(method_name).select { |e| e.name == name } values.empty? ? false : values #(values.size == 1 ? values.first : values) end |
#schemes ⇒ Array<String>
return empty array when the manifest not include http or https scheme(s) of data
Returns all data elements.
230 231 232 233 234 235 236 |
# File 'lib/android/manifest.rb', line 230 def schemes return unless schemes? data.select {|d| !d.scheme.nil? && !['http', 'https'].include?(d.scheme) } .map { |d| d.scheme } .uniq end |
#schemes? ⇒ Boolean
the deep links exists with non-http or non-https in data element or not
241 242 243 |
# File 'lib/android/manifest.rb', line 241 def schemes? browsable? && data.any? { |d| !['http', 'https'].include?(d.scheme) } end |