Skip to content

Commit 77f0fc5

Browse files
committed
add some yard docs
1 parent d4ba7e0 commit 77f0fc5

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

lib/anvl.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
require 'anvl/element'
22
require 'anvl/document'
33
module ANVL
4+
# Parse an ANVL document into a hash
45
def self.parse *args
56
Document.parse *args
67
end
78

9+
# Serialize a Hash to an ANVL string
810
def self.to_anvl *args
911
anvl = Document.parse *args
1012
anvl.to_s

lib/anvl/document.rb

+22-6
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
module ANVL
22
class Document # < Hash
3+
# Parse an ANVL formatted string into an ANVL::Document
4+
# @param String
35
def self.parse str
46
anvl = self.new str
57
anvl
68
end
79

10+
# ANVL key/value pairs
811
attr_reader :entries
912

10-
def initialize obj = nil
13+
# @param [String, Hash] obj optional ANVL formatted string or hash values
14+
def initialize anvl_string_or_hash = nil
1115
@entries = Array.new
1216

13-
case obj
17+
case anvl_string_or_Hash
1418
when Hash
15-
self.push obj
19+
self.push anvl_string_or_hash
1620

1721
when String
18-
lines = obj.gsub(/\s?\n\s+/, ' ').split("\n")
22+
lines = anvl_string_or_hash.gsub(/\s?\n\s+/, ' ').split("\n")
1923

2024
lines.each_with_index do |str, i|
2125
case str
@@ -28,20 +32,22 @@ def initialize obj = nil
2832
end
2933
end
3034

31-
end if obj
35+
end if anvl_string_or_hash
3236

3337
add_entries_methods
3438

3539
gc!
3640
end
3741

42+
# @return [String] an ANVL-formatted string
3843
def to_s
3944
gc!
4045
@entries.map do |obj|
4146
obj.to_anvl
4247
end.join "\n"
4348
end
4449

50+
# @return [Hash] an ordinary hash representation of the ANVL document
4551
def to_h
4652
gc!
4753
h = {}
@@ -58,6 +64,11 @@ def to_h
5864
h
5965
end
6066

67+
# Retrieve an ANVL entry
68+
# @param [String] display_label
69+
# @param [Hash] args
70+
# @option args [Boolean] :raw
71+
# @return [Array, String]
6172
def [] display_label, args = {}
6273
v = @entries.select { |x| x =~ display_label }
6374
v &&= v.map { |x| x.to_s } unless args[:raw]
@@ -66,6 +77,10 @@ def [] display_label, args = {}
6677
end
6778
alias_method :fetch, :[]
6879

80+
# Set an ANVL key/value pair
81+
# @param [String] display_label
82+
# @param [String] value
83+
# @param [Boolean] append (if false (the default), it will overwrite any existing tags for the label)
6984
def []= display_label, value, append = false
7085
label = convert_label display_label
7186
value = [value] unless value.is_a? Array
@@ -79,9 +94,10 @@ def []= display_label, value, append = false
7994
end
8095
end
8196
end
82-
8397
alias_method :store, :[]=
8498

99+
# Append an ANVL key/value pair to the document
100+
# @param [Hash] key => value to append
85101
def push hash
86102
hash.each do |label, value|
87103
self.store label, value, true

0 commit comments

Comments
 (0)