Module: BEL::Gen::DocumentHeader

Included in:
Nanopub
Defined in:
lib/bel/gen/document_header.rb

Overview

The DocumentHeader module defines methods that generate a random document header for the Nanopub::Nanopub metadata.

Instance Method Summary collapse

Instance Method Details

#document_authorsString

Returns randomly chosen document authors.

Returns:

  • (String)

    random document authors



80
81
82
83
84
85
86
# File 'lib/bel/gen/document_header.rb', line 80

def document_authors
  Rantly {
    array(range(1, 5)) {
      "#{sized(6) { string(:alpha) }} #{sized(2) { string(:upper) }}"
    }.join('|')
  }
end

#document_contact_infoString

Returns a randomly chosen document contact info.

Returns:

  • (String)

    a random document contact info



74
75
76
# File 'lib/bel/gen/document_header.rb', line 74

def document_contact_info
  Rantly { email }
end

Returns a randomly chosen document copyright.

Returns:

  • (String)

    a random document copyright



68
69
70
# File 'lib/bel/gen/document_header.rb', line 68

def document_copyright
  "You, (c) #{Time.now.year}"
end

#document_descriptionString

Returns a randomly chosen document description.

Returns:

  • (String)

    a random document description



23
24
25
26
27
28
29
30
31
# File 'lib/bel/gen/document_header.rb', line 23

def document_description
  Rantly {
    array(range(10,50)) {
      sized(range(3,8)) {
        string(:alpha).capitalize
      }
    }.join(' ').capitalize
  }
end

#document_header(options = {}) ⇒ Hash

Returns a random document header.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :name (String)

    the document name override

  • :description (String)

    the document description override

  • :version (String)

    the document version override

  • :copyright (String)

    the document copyright override

  • :contact_info (String)

    the document contact info override

  • :authors (String)

    the document authors override

  • :licenses (String)

    the document licenses override

Returns:

  • (Hash)

    random document header



116
117
118
119
120
121
122
123
124
125
126
# File 'lib/bel/gen/document_header.rb', line 116

def document_header(options = {})
  {
    :Name        => options[:name]         || document_name,
    :Description => options[:description]  || document_description,
    :Version     => options[:version]      || document_version,
    :Copyright   => options[:copyright]    || document_copyright,
    :ContactInfo => options[:contact_info] || document_contact_info,
    :Authors     => options[:authors]      || document_authors,
    :Licenses    => options[:licenses]     || document_licenses,
  }
end

#document_licensesString

Returns randomly chosen document licenses.

Returns:

  • (String)

    random document licenses



90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/bel/gen/document_header.rb', line 90

def document_licenses
  Rantly {
    choose(
      'Creative Commons Attribution (BY)',
      'Creative Commons Share-alike (BY-SA)',
      'Creative Commons Non-commercial (NC)',
      'Creative Commons No Derivative Works (ND)',
      'Open Data Commons Open Database License',
      'Open Data Commons Attribution License',
      'Open Data Commons Public Domain Dedication and License',
      'Public Domain',
    )
  }
end

#document_nameString

Returns a randomly chosen document name.

Returns:

  • (String)

    a random document name



13
14
15
16
17
18
19
# File 'lib/bel/gen/document_header.rb', line 13

def document_name
  Rantly {
    array(range(1,4)) {
      string(:alpha).capitalize
    }.join(' ')
  }
end

#document_versionString

Returns a randomly chosen document version.

Returns:

  • (String)

    a random document version



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/bel/gen/document_header.rb', line 35

def document_version
  Rantly {
    if boolean
      # semver
      numeric = -> { range(0, 15) }
      "#{numeric.call}.#{numeric.call}.#{numeric.call}"
    else
      # rolling date
      year  = -> {
        range(2000, Time.now.year)
      }
      month = -> {
        choose(
          '01', '02', '03', '04', '05', '06',
          '07', '08', '09', '10', '11', '12'
        )
      }
      day   = -> {
        choose(
          '01', '02', '03', '04', '05', '06',
          '07', '08', '09', '10', '11', '12',
          '13', '14', '15', '16', '17', '18',
          '19', '20', '21', '22', '23', '24',
          '25', '26', '27', '28'
        )
      }
      "#{year.call}#{month.call}#{day.call}"
    end
  }
end