Class: Gottani::Core

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

Overview

Gottani::Core

Constant Summary collapse

FORMAT =
{
  tab: Gottani::Tab,
  space2: Gottani::Space2,
  space4: Gottani::Space4,
  markdown: Gottani::Markdown,
  hatena: Gottani::Hatena
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, base) ⇒ Core

Returns a new instance of Core.



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

def initialize(type, base)
  instance = FORMAT[type].new
  @common = instance.send "#{type}_to_common", base
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/gottani_core.rb', line 26

def method_missing(method_name, *args, &block)
  method_name.match(/^to_(.*)$/)
  super unless Regexp.last_match[1]
  instance = FORMAT[Regexp.last_match[1].to_sym].new
  return instance.send("to_#{Regexp.last_match[1]}", @common) if instance
  super
end

Instance Attribute Details

#commonObject (readonly)

Returns the value of attribute common.



12
13
14
# File 'lib/gottani_core.rb', line 12

def common
  @common
end

#typeObject (readonly)

Returns the value of attribute type.



12
13
14
# File 'lib/gottani_core.rb', line 12

def type
  @type
end