Class: Md2site::Testdata

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

Overview

テストデータクラス

Instance Method Summary collapse

Constructor Details

#initialize(src_data_dir, templatedir, hash, num = 1) ⇒ Testdata

初期化

Parameters:

  • src_data_dir (String)

    テストデータのコピー元ディレクトリ

  • templatedir (String)

    テストデータのテンプレートディレクトリ

  • hash (Hash)

    修正対象ハッシュ

  • num (Integer) (defaults to: 1)


12
13
14
15
16
17
18
19
# File 'lib/md2site/testdata.rb', line 12

def initialize(src_data_dir, templatedir, hash, num=1)
  @hash = hash
  @src_data_dir = src_data_dir
  @templatedir = templatedir
  @content_division = @hash["CONTENT_DIVISION_WAY"]
  check_additional_conf(@hash)
  require_htmlutils(num) unless defined?(HTMLUtils)
end

Instance Method Details

#check_additional_conf(hash) ⇒ void

This method returns an undefined value.

URLに応じてハッシュの内容を修正する

Parameters:

  • hash (Hash)

    修正対象ハッシュ



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/md2site/testdata.rb', line 26

def check_additional_conf(hash)
  url = hash["url"]
  hash["functions_variable"] ||= ""
  hash["functions_static"]   ||= %Q(ROOT_TEMPLATE_FUNCTIONS_VARIABLE=#{%q(${ABSOLUTE_PATH_ROOT_TEMPLATE}/functions_variable.erb)})
  hash["contentDivisionWay"] ||= ""

  case url
  when /www\.toppers\.jp/
    hash["contentDivisionWay"] = "CONTENT_DIVISION_WAY=0"
    hash["functions_variable"] = %Q(ROOT_TEMPLATE_FUNCTIONS_VARIABLE=#{%q(${ABSOLUTE_PATH_ROOT_TEMPLATE}/functions_variable.erb)})
    hash["functions_static"]   = %Q(ROOT_TEMPLATE_FUNCTIONS_STATIC=#{%q(${ABSOLUTE_PATH_ROOT_TEMPLATE}/functions_static.erb)})
  end
end

#require_htmlutils(num = 1) ⇒ Array<String>

適切なHTMLファイル分割クラスの読み込み

Parameters:

  • num (Integer) (defaults to: 1)

Returns:

  • (Array<String>)

    URLに応じた適切なHTMLファイル分割クラスの読み込み



77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/md2site/testdata.rb', line 77

def require_htmlutils(num=1)
  if @content_division
    num = @content_division.to_i
  end

  case num
  when 0
    require "md2site/htmlutils0"
  else
    require "md2site/htmlutils"
  end
end

#template_dir_arrayArray<String>

URLに応じたテンプレートディレクトリを得る

Returns:

  • (Array<String>)

    URLに応じたテンプレートディレクトリの配列



44
45
46
47
48
49
50
51
52
53
# File 'lib/md2site/testdata.rb', line 44

def template_dir_array
  array = [@templatedir]

  case @hash["url"]
  when /www\.toppers\.jp/
    array << TEMPLATE_DIR2
  end

  array
end

#testdata_dir_arrayArray<String>

URLに応じたテストデータディレクトリを得る

Returns:

  • (Array<String>)

    URLに応じたテストデータディレクトリの配列



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/md2site/testdata.rb', line 59

def testdata_dir_array
  array = []

  case @hash["url"]
  when /www\.toppers\.jp/
    array << TESTDATA_DIR_TOPPERS
  when /northern-cross\.info/
    array << TESTDATA_DIR_TOPPERS
  end

  array
end