Class: Android::Manifest::Component

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

Overview

<activity>, <service>, <receiver> or <provider> element in <application> element of the manifest file.

Constant Summary collapse

TYPES =

component types

['service', 'activity', 'receiver', 'provider']

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(elem) ⇒ Component

Returns a new instance of Component.

Parameters:

  • elem (REXML::Element)

    target element

Raises:

  • (ArgumentError)

    when elem is invalid.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/android/manifest.rb', line 37

def initialize(elem)
  raise ArgumentError unless Component.valid?(elem)
  @elem = elem
  @type = elem.name
  @name = elem.attributes['name']
  @intent_filters = []
  unless elem.elements['intent-filter'].nil?
    elem.elements['intent-filter'].each do |e|
      next unless e.instance_of? REXML::Element
      @intent_filters << IntentFilter.parse(e)
    end
  end
  @metas = []
  elem.each_element('meta-data') do |e|
    @metas << Meta.new(e)
  end
end

Instance Attribute Details

#elemREXML::Element (readonly)

Returns:

  • (REXML::Element)


32
33
34
# File 'lib/android/manifest.rb', line 32

def elem
  @elem
end

#intent_filtersArray<Manifest::IntentFilter> (readonly)

Returns:



28
29
30
# File 'lib/android/manifest.rb', line 28

def intent_filters
  @intent_filters
end

#metasArray<Manifest::Meta> (readonly)

Returns:



30
31
32
# File 'lib/android/manifest.rb', line 30

def metas
  @metas
end

#nameString (readonly)

Returns component name.

Returns:

  • (String)

    component name



26
27
28
# File 'lib/android/manifest.rb', line 26

def name
  @name
end

#typeString (readonly)

Returns type string in TYPES.

Returns:

  • (String)

    type string in TYPES



24
25
26
# File 'lib/android/manifest.rb', line 24

def type
  @type
end

Class Method Details

.valid?(elem) ⇒ Boolean

the element is valid Component element or not

Parameters:

  • elem (REXML::Element)

    xml element

Returns:

  • (Boolean)


17
18
19
20
21
# File 'lib/android/manifest.rb', line 17

def self.valid?(elem)
  TYPES.include?(elem.name.downcase)
rescue => e
  false
end