Class: Referee::Renderable

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

Overview

Abstract class defining how renderable resources must behave.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRenderable



6
7
8
# File 'lib/referee/renderable.rb', line 6

def initialize
  fail 'Abstract class Renderable may not be instantiated!'
end

Instance Attribute Details

#swift_typeObject

Returns the value of attribute swift_type.



4
5
6
# File 'lib/referee/renderable.rb', line 4

def swift_type
  @swift_type
end

#typeObject

Returns the value of attribute type.



4
5
6
# File 'lib/referee/renderable.rb', line 4

def type
  @type
end

Instance Method Details

#bundle_accessor(bundle_id) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/referee/renderable.rb', line 25

def bundle_accessor(bundle_id)
  if bundle_id
    "[NSBundle bundleWithIdentifier:\"#{bundle_id}\"]"
  else
    '[NSBundle mainBundle]'
  end
end

#declarationObject

NOTE: Subclasses must implement this method.



11
12
13
# File 'lib/referee/renderable.rb', line 11

def declaration
  fail 'Subclasses must implement declaration()!'
end

#implementationObject

NOTE: Subclasses must implement this method.



16
17
18
# File 'lib/referee/renderable.rb', line 16

def implementation
  fail 'Subclasses must implement implementation()!'
end

#methodize_name(name) ⇒ Object



41
42
43
# File 'lib/referee/renderable.rb', line 41

def methodize_name(name)
  name.gsub(/[^a-zA-Z0-9]/, '')
end

#simple_method_declaration(name) ⇒ Object



45
46
47
48
# File 'lib/referee/renderable.rb', line 45

def simple_method_declaration(name)
  clean_name = methodize_name(name)
  "- (#{@type})#{clean_name};"
end

#simple_method_implementation(name, body) ⇒ Object



50
51
52
53
# File 'lib/referee/renderable.rb', line 50

def simple_method_implementation(name, body)
  clean_name = methodize_name(name)
  "- (#{@type})#{clean_name}\n{\n\treturn #{body};\n}"
end

#simple_swift_method(name, body) ⇒ Object



55
56
57
58
# File 'lib/referee/renderable.rb', line 55

def simple_swift_method(name, body)
  clean_name = methodize_name(name)
  "func #{clean_name}() -> #{@swift_type} {\n\t\t\treturn #{body}\n\t\t}"
end

#simple_swift_string_case(name) ⇒ Object



60
61
62
63
# File 'lib/referee/renderable.rb', line 60

def simple_swift_string_case(name)
  clean_name = methodize_name(name)
  "case #{clean_name} = \"#{name}\""
end

#swift_bundle_accessor(bundle_id) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/referee/renderable.rb', line 33

def swift_bundle_accessor(bundle_id)
  if bundle_id
    "NSBundle(identifier: \"#{bundle_id}\")"
  else
    'NSBundle.mainBundle()'
  end
end

#swift_implementationObject

NOTE: Subclasses must implement this method.



21
22
23
# File 'lib/referee/renderable.rb', line 21

def swift_implementation
  fail 'Subclasses must implement swift_implementation()!'
end