Class: Arxutils::Arx

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

Overview

スキーマ設定に基づき、テンプレートから変換する

Instance Method Summary collapse

Constructor Details

#initialize(data, fname) ⇒ Arx

スキーマ設定配列を、テンプレートで参照可能になるように展開する



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/arxutils/arx.rb', line 8

def initialize( data , fname )
  # テンプレートファイルへのパス
  @fname = fname

  # スキーマ設定配列
  # スキーマ設定とは以下をキーにもつハッシュである
  # :flist
  # :classname
  # :classname_downcase
  # :items
  #  フィールド名, 型, null許容 の配列
  # :plural
  # :relation
  @data = data

  # スキーマ設定の:itemsの値を展開後格納するためのStructクラス
  @@field ||= Struct.new("Field" , :name, :type, :null ) 

  if @data[:items]
    @data[:ary] = @data[:items].map{ |x| @@field.new( *x ) }
  else
    @data[:ary] = []
  end
end

Instance Method Details

#createObject

テンプレートファイルを元にした変換結果を返す



34
35
36
37
38
39
# File 'lib/arxutils/arx.rb', line 34

def create
  contents = File.open( @fname ).read
  erb = ERB.new(contents)
  content = erb.result(binding)
  content
end