Sha256: 827760d8e8f7bdd5d4a3b6e4b94f58dc3da023decb1c156791e6250e738053d3
Contents?: true
Size: 1.32 KB
Versions: 14
Compression:
Stored size: 1.32 KB
Contents
module Apstrings class Line attr_reader :content attr_accessor :in_comment def initialize(line) @content = line @in_comment = false raise "ERROR : Line does not end with `;`, #{line}" unless valid? end def empty_line? /^\s*$/.match(content) || false end def whole_comment /((^\/\*(.+)\*\/)|(^\/\/(.+)))/.match(content).to_s end def whole_comment? !(whole_comment.empty?) end def open_comment /^\/\*(.+)$/.match(content).to_s end def open_comment? !(open_comment.empty?) end def close_comment /^(.+)\*\/\s*$/.match(content).to_s end def close_comment? !(close_comment.empty?) end def key_value_pair? !!(/^\s*"([^"]+)"\s*=/.match(content)) end def cleaned_content content.gsub(/;\s*$/, "") end def valid? if key_value_pair? !!(/;[\s]*$/.match(content)) else true end end def key if key_value_pair? cleaned_content.partition(/"\s*=\s*"/)[0].gsub!(/(^"|"$)/, "") end end def value if key_value_pair? cleaned_content.partition(/"\s*=\s*"/)[2].gsub!(/(^"|"$)/, "") end end def is_comment? whole_comment? || open_comment? || close_comment? || in_comment end end end
Version data entries
14 entries across 14 versions & 1 rubygems