Class: CodeModels::Parser
- Inherits:
-
Object
- Object
- CodeModels::Parser
- Defined in:
- lib/codemodels/parser.rb
Constant Summary collapse
- DEFAULT_INTERNAL_ENCODING =
'UTF-8'
Instance Attribute Summary collapse
-
#internal_encoding ⇒ Object
readonly
Returns the value of attribute internal_encoding.
Instance Method Summary collapse
-
#initialize(internal_encoding = DEFAULT_INTERNAL_ENCODING) ⇒ Parser
constructor
A new instance of Parser.
- #parse_artifact(artifact) ⇒ Object
-
#parse_code(code) ⇒ Object
Deprecated: use parse_string.
- #parse_file(path, file_encoding = nil) ⇒ Object
- #parse_string(code) ⇒ Object
Constructor Details
#initialize(internal_encoding = DEFAULT_INTERNAL_ENCODING) ⇒ Parser
Returns a new instance of Parser.
13 14 15 16 |
# File 'lib/codemodels/parser.rb', line 13 def initialize(internal_encoding=DEFAULT_INTERNAL_ENCODING) @internal_encoding = internal_encoding puts "WARN using an internal encoding different from the local encoding..." if "".encoding.name!=internal_encoding end |
Instance Attribute Details
#internal_encoding ⇒ Object (readonly)
Returns the value of attribute internal_encoding.
11 12 13 |
# File 'lib/codemodels/parser.rb', line 11 def internal_encoding @internal_encoding end |
Instance Method Details
#parse_artifact(artifact) ⇒ Object
18 19 20 |
# File 'lib/codemodels/parser.rb', line 18 def parse_artifact(artifact) internal_parse_artifact(artifact) end |
#parse_code(code) ⇒ Object
Deprecated: use parse_string
31 32 33 |
# File 'lib/codemodels/parser.rb', line 31 def parse_code(code) parse_string(code) end |
#parse_file(path, file_encoding = nil) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/codemodels/parser.rb', line 22 def parse_file(path,file_encoding=nil) file_encoding = internal_encoding unless file_encoding code = IO.read(path,{ :encoding => file_encoding, :mode => 'rb'}) code = code.encode(internal_encoding) artifact = FileArtifact.new(path,code) internal_parse_artifact(artifact) end |
#parse_string(code) ⇒ Object
35 36 37 38 39 |
# File 'lib/codemodels/parser.rb', line 35 def parse_string(code) raise "Wrong encoding: it is #{code.encoding.name}, internally expected #{internal_encoding}" unless code.encoding.name==internal_encoding artifact = StringArtifact.new(code) internal_parse_artifact(artifact) end |