module Bismas

Constants

CATEGORY_CHAR_SKIP
CHARS
DEFAULT_CATEGORY_LENGTH

See parameter FELD in BISMAS *.CAT

DEFAULT_ENCODING

Default file encoding

DEFAULT_PADDING_LENGTH

See parameter FUELLZEICHEN in BISMAS *.CFG

REGEX
VERSION

Public Instance Methods

amend_encoding(options, default_encoding = DEFAULT_ENCODING) click to toggle source
    # File lib/bismas.rb
143 def amend_encoding(options, default_encoding = DEFAULT_ENCODING)
144   encoding = (options[:encoding] || default_encoding).to_s
145 
146   options[:encoding] = encoding.start_with?(':') ?
147     default_encoding.to_s + encoding : encoding
148 end
chars(options = {}) click to toggle source
   # File lib/bismas.rb
52 def chars(options = {})
53   encoding = amend_encoding(options).split(':').last
54 
55   Hash[CHARS.map { |k, v| [k, begin
56     v.encode(encoding)
57   rescue Encoding::UndefinedConversionError
58     v.dup.force_encoding(encoding)
59   end] }]
60 end
encode(record, encoding) click to toggle source
    # File lib/bismas.rb
128 def encode(record, encoding)
129   return record unless encoding
130 
131   fallback = Hash.new { |h, k| h[k] = '?' }
132 
133   record.each { |key, values|
134     values.each { |value| value.encode!(encoding, fallback: fallback) }
135 
136     unless fallback.empty?
137       chars = fallback.keys.map(&:inspect).join(', '); fallback.clear
138       warn "Undefined characters at #{$.}:#{key}: #{chars}"
139     end
140   }
141 end
execute(execute, &block) click to toggle source
    # File lib/bismas.rb
 93 def execute(execute, &block)
 94   block ||= method(:abort)
 95 
 96   outer_binding = nil
 97 
 98   execute.map { |value|
 99     value = Array(value).map { |code| case code
100       when /\.rb\z/i then File.readable?(code) ?
101         File.read(code) : block["No such file: #{code}"]
102       when String    then code
103       else block["Invalid code: #{code.inspect}"]
104     end }
105 
106     lambda { |bind|
107       !outer_binding ? outer_binding = bind :
108         (outer_binding.local_variables - bind.local_variables).each { |v|
109           bind.local_variable_set(v, outer_binding.local_variable_get(v)) }
110 
111       value.each { |code| eval(code, bind) }
112     }
113   }
114 end
execute_options(options, keys = nil, &block) click to toggle source
   # File lib/bismas.rb
88 def execute_options(options, keys = nil, &block)
89   execute(options.values_at(*keys ||
90     %i[execute_before execute execute_mapped execute_after]), &block)
91 end
filter(klass, options, &block) click to toggle source
   # File lib/bismas.rb
69 def filter(klass, options, &block)
70   Filter.run(klass, options, &block)
71 end
input_options(options, category_length = options[:category_length]) click to toggle source
   # File lib/bismas.rb
77 def input_options(options, category_length = options[:category_length])
78   {
79     encoding:        options[:input_encoding],
80     key:             options[:input_key],
81     strict:          options[:strict],
82     silent:          options[:silent],
83     legacy:          options[:legacy],
84     category_length: category_length
85   }
86 end
mapping(mapping, &block) click to toggle source
    # File lib/bismas.rb
116 def mapping(mapping, &block)
117   block ||= method(:abort)
118 
119   Mapping[case mapping
120     when nil, Hash    then mapping
121     when /\A\{.*\}\z/ then safe_yaml.load(mapping)
122     when String       then File.readable?(mapping) ?
123       safe_yaml.load_file(mapping) : block["No such file: #{mapping}"]
124     else block["Invalid mapping: #{mapping.inspect}"]
125   end]
126 end
regex(options = {}, chars = chars(options)) click to toggle source
   # File lib/bismas.rb
62 def regex(options = {}, chars = chars(options))
63   category_length = options[:category_length] || DEFAULT_CATEGORY_LENGTH
64 
65   Hash[REGEX.map { |k, v| [k, Regexp.new(v % chars)] }].update(category:
66     /[^#{chars.values_at(*CATEGORY_CHAR_SKIP).join}]{#{category_length}}/)
67 end
require_gem(gem, lib = gem, &block) click to toggle source
    # File lib/bismas.rb
150 def require_gem(gem, lib = gem, &block)
151   require lib
152 rescue LoadError => err
153   block ||= method(:abort)
154   block["Please install the `#{gem}' gem. (#{err})"]
155 end
safe_yaml() click to toggle source
    # File lib/bismas.rb
157 def safe_yaml
158   require_gem 'safe_yaml', 'safe_yaml/load'
159   SafeYAML
160 end
to_xml(options, &block) click to toggle source
   # File lib/bismas.rb
73 def to_xml(options, &block)
74   XML.run(options, &block)
75 end