nitc :: ReadmeMetric
nitc :: ReadmeMetric :: _has_package_dir
Ismpackage
in its own directory?
nitc :: ReadmeMetric :: _package_path
Path to the packagenitc :: ReadmeMetric :: _readme_path
Return the path to thempackage
Readme file
nitc :: ReadmeMetric :: defaultinit
nitc :: ReadmeMetric :: has_package_dir=
Ismpackage
in its own directory?
nitc :: ReadmeMetric :: has_readme=
Doesmpackage
has a Readme file?
nitc :: ReadmeMetric :: mpackage=
Package this Readme is aboutnitc :: ReadmeMetric :: package_path=
Path to the packagenitc :: ReadmeMetric :: readme_path
Return the path to thempackage
Readme file
nitc :: ReadmeMetric :: readme_path=
Return the path to thempackage
Readme file
nitc :: ReadmeMetric :: to_csv_record
Renderself
as a CsvDocument record
nitc :: ReadmeMetric :: value_or_zero
Return the value associated withkey
or 0
.
nitc $ ReadmeMetric :: SELF
Type of this instance, automatically specialized in every classcore :: HashCollection :: _array
core :: HashCollection :: _capacity
core :: HashCollection :: _first_item
nitc :: ReadmeMetric :: _has_package_dir
Ismpackage
in its own directory?
core :: HashCollection :: _last_accessed_key
The last key accessed (used for cache)core :: HashCollection :: _last_accessed_node
The last node accessed (used for cache)core :: HashCollection :: _last_item
nitc :: ReadmeMetric :: _package_path
Path to the packagenitc :: ReadmeMetric :: _readme_path
Return the path to thempackage
Readme file
core :: HashCollection :: _the_length
serialization :: Serializable :: accept_inspect_serializer_core
serialization :: Serializable :: accept_json_serializer
Refinable service to customize the serialization of this class to JSONserialization :: Serializable :: accept_msgpack_attribute_counter
Hook to customize the behavior of theAttributeCounter
serialization :: Serializable :: accept_msgpack_serializer
Hook to customize the serialization of this class to MessagePackserialization :: Serializable :: add_to_bundle
Called by[]=
to dynamically choose the appropriate method according
core :: HashCollection :: array
core :: HashCollection :: array=
core :: HashCollection :: capacity
core :: HashCollection :: capacity=
core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
serialization :: Serializable :: core_serialize_to
Actual serialization ofself
to serializer
nitc :: ReadmeMetric :: defaultinit
core :: Map :: defaultinit
core :: HashCollection :: defaultinit
core :: HashMap :: defaultinit
core :: MapRead :: defaultinit
core :: Object :: defaultinit
core :: MapRead :: filter_keys
Return all elements ofkeys
that have a value.
core :: HashCollection :: first_item
core :: HashCollection :: first_item=
serialization :: Serializable :: from_deserializer
Create an instance of this class from thedeserializer
core :: MapRead :: get_or_default
Get the item atkey
or return default
if not in map
core :: MapRead :: get_or_null
Get the item atkey
or null if key
is not in the map.
core :: HashCollection :: gt_collide
Count and update length of collisions fornode_at_idx
nitc :: ReadmeMetric :: has_package_dir=
Ismpackage
in its own directory?
nitc :: ReadmeMetric :: has_readme=
Doesmpackage
has a Readme file?
core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
core :: MapRead :: keys_sorted_by_values
Return an array of all keys sorted with their values usingcomparator
.
core :: HashCollection :: last_accessed_key
The last key accessed (used for cache)core :: HashCollection :: last_accessed_key=
The last key accessed (used for cache)core :: HashCollection :: last_accessed_node
The last node accessed (used for cache)core :: HashCollection :: last_accessed_node=
The last node accessed (used for cache)core :: HashCollection :: last_item
core :: HashCollection :: last_item=
core :: MapRead :: lookup_all_values
Search all the values inpe.greaters
.
core :: MapRead :: lookup_values
Combine the values inpe.greaters
from the most smaller elements that have a value.
nitc :: ReadmeMetric :: mpackage=
Package this Readme is aboutserialization :: Serializable :: msgpack_extra_array_items
Hook to request a larger than usual metadata arraycore :: Object :: native_class_name
The class name of the object in CString format.core :: HashCollection :: node_at_idx
Return the node associated with the key (but with the index already known)core :: Object :: output_class_name
Display class name on stdout (debug only).nitc :: ReadmeMetric :: package_path=
Path to the packagecore :: MapRead :: provide_default_value
Called by the underling implementation of[]
to provide a default value when a key
has no value
nitc :: ReadmeMetric :: readme_path
Return the path to thempackage
Readme file
nitc :: ReadmeMetric :: readme_path=
Return the path to thempackage
Readme file
core :: HashCollection :: remove_node
Remove the node assosiated with the keyserialization :: Serializable :: serialize_msgpack
Serializeself
to MessagePack bytes
serialization :: Serializable :: serialize_to
Serializeself
to serializer
serialization :: Serializable :: serialize_to_json
Serializeself
to JSON
serialization :: Serializable :: serialize_to_or_delay
Accept references or force direct serialization (usingserialize_to
)
core :: HashCollection :: st_collide
Count and update length of collisions forstore
core :: HashCollection :: the_length
core :: HashCollection :: the_length=
nitc :: ReadmeMetric :: to_csv_record
Renderself
as a CsvDocument record
core :: MapRead :: to_map_comparator
A comparator that compares things with their values in self.serialization :: Serializable :: to_pretty_json
Serializeself
to plain pretty JSON
nitc :: ReadmeMetric :: value_or_zero
Return the value associated withkey
or 0
.
core :: MapRead :: values_sorted_by_key
Return an array of all values sorted with their keys usingcomparator
.
Serializer::serialize
# Readme metrics associated to a Package
class ReadmeMetric
super HashMap[String, Int]
# Package this Readme is about
var mpackage: MPackage
# Render `self` as a CsvDocument record
fun to_csv_record(keys: ArraySet[String]): Array[String] do
var record = new Array[String]
record.add mpackage.full_name
for key in keys do
if key == keys.first then continue
var value = if self.has_key(key) then self[key] else 0
record.add value.to_s
end
return record
end
# Return the value associated with `key` or `0`.
fun value_or_zero(key: String): Int do
return if self.has_key(key) then self[key] else 0
end
# Print `self` on stdout
fun to_console(toolcontext: ToolContext) do
print toolcontext.format_h2("\n ## package {mpackage} ({readme_path or else "no readme"})")
for key, value in self do
print " * {key} {value}"
end
end
# Collect metrics about `mpackage`
fun collect_metrics do
if not has_package_dir then
print "Warning: no source file for `{mpackage}`"
self["has_package"] = 0
return
end
self["has_package"] = 1
if not has_readme then
print "Warning: no readme file for `{mpackage}`"
self["has_readme"] = 0
return
end
self["has_readme"] = 1
self["md_lines"] = md_lines.length
var parser = new MdParser
var node = parser.parse(md_lines.join("\n"))
var v = new MarkdownMetrics
v.enter_visit(node)
for md_node, value in v.nodes_counter do
self[md_node] = value
end
for level, value in v.headings_counter do
self["HL {level}"] = value
end
end
# Path to the package
var package_path: nullable SourceFile is lazy do return mpackage.location.file
# Is `mpackage` in its own directory?
var has_package_dir: Bool is lazy do
var path = package_path
if path == null then return false
return not path.filename.has_suffix(".nit")
end
# Return the path to the `mpackage` Readme file
var readme_path: nullable String is lazy do
var package_path = self.package_path
if package_path == null then return null
return package_path.filename / "README.md"
end
# Does `mpackage` has a Readme file?
var has_readme: Bool is lazy do
var readme_path = self.readme_path
if readme_path == null then return false
return readme_path.to_s.file_exists
end
# Read markdown lines
#
# Returns an empty array if the Readme does not exist.
var md_lines: Array[String] is lazy do
var path = readme_path
if path == null then return new Array[String]
return path.to_path.read_lines
end
end
src/metrics/readme_metrics.nit:112,1--205,3